开发者

Help with CAML query for accessing document types in document library

开发者 https://www.devze.com 2023-02-01 13:13 出处:网络
I have a Document Library on SharePoint which hosts documents of different types and i have a custom search web part which is supposed to search the library and display documents based on search type

I have a Document Library on SharePoint which hosts documents of different types and i have a custom search web part which is supposed to search the library and display documents based on search type along with other search criteria.Problem is i cant search for the document type, My CAML query is as follows:

           SPWeb web = site.OpenWeb();
           SPList document = web.Lists["Training Docs"];
           SPListItemCollection objItemcoll;
           SPQuery objQuery = new SPQuery();
           objQuery.Query = "<Where><Contains><FieldRef Name=\"Name\"/>
           <Value Type=\"Text\"></Value>doc</Contains></Where>";
           objItemcoll = document.GetItems(objQuery);
           if (objItemcoll.Count > 0)
           {
               foreach (SPListItem i开发者_如何学Ctem in objItemcoll)
               {
                   //Binding To Grid;
               }
           }
       }

Im guessing the fault is with value type=" " . Any help would be appreciated.


Try:

<Where><Contains><FieldRef Name='FileLeafRef' /><Value Type='Text'>doc</Value></Contains></Where>

I created this query using the U2U CAML Query Builder. You might want to try it. It is the resource for creating CAML query strings for SPQuery objects.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号