Convert current list view filter into CAML query

别等时光非礼了梦想. 提交于 2019-12-24 05:46:27

问题


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:

  1. Create a view for your list with required filters.
  2. Open the SharePoint CAML Query Helper.
  3. Put your credentials, open the required site.
  4. It loads all the lists at right side, double click the required list.
  5. Click Open List Views.
  6. Double click the view which you have created previously.
  7. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!