问题
I am working in sharepoint2010,
I have a custom list. Employees
.
http:/lists/employees/allitems.aspx
I do some filtering in the list, so the URL will automatically become like this
http:///lists/employees/allitems.aspx?View={guid}&filterField1=fieldname&FilterValue1=123......
I want to convert this URL into CAML query, or in any other way i want to get the filtered datas as DataTable.
Is there any feature available in SharePoint SDK or any suggestion for this?
Thanks in advance.
回答1:
your caml query like this:
<Query> <Where>
<Eq> <FieldRef Name='Title' /> <Value Type='Text'>123</Value> </Eq>
</Where> </Query>
and your C# code:
SPQuery query = new SPQuery();
query.Query = caml;
SPContext.Current.List.GetItems(query).GetDataTable();
回答2:
After some search, i got to know it is not possible to convert into CAML automatically, so i decided to go for parsing myself.
回答3:
Yes. it is possible.! Download SharePoint CAML Query Helper from CodePlex. This a very useful tool for constructing CAML query.
Now follow below steps:
- Create a view for your list with required filters.
- Open the SharePoint CAML Query Helper.
- Put your credentials, open the required site.
- It loads all the lists at right side, double click the required list.
- Click Open List Views.
- Double click the view which you have created previously.
- Now it will display full query, select from "" to and use it in your code (replace value with your code values).
来源:https://stackoverflow.com/questions/15864420/convert-current-list-view-filter-into-caml-query