user388969
user388969

Reputation: 341

CAML query to retrieve files from Document libraries and Page Library

I am trying to search in Pages and Document libraries once. Is there a template in CAML that works for both document libraries and pages libraries.

I have this for pages library only but it doesn't search document libraries

siteDataQuery.Lists ="<listsLists ServerTemplate=\"850\" />"; 

Full Code

 sing (SPWeb web = new SPSite(SPContext.Current.Site.RootWeb.Url).OpenWeb())
                {

                    siteDataQuery.ViewFields = "<FieldRef  Nullable=\"TRUE\" Name=\"FileRef\"/><FieldRef Name=\"Title\"/>";
                    siteDataQuery.Lists = "<Lists ServerTemplate=\"101\" />";
                    siteDataQuery.RowLimit = 500;
                    siteDataQuery.Webs = "<Webs Scope=\"Recursive\"/>";

                    siteDataQuery.Query = "<Where><And><Eq><FieldRef Name='ContentType' /><Value Type='Computed'Page-Archive Item</Value></Eq><Eq><FieldRef Name='Metadata' LookupId='True' /><Value Type='Integer'>447</Value></Eq></And></Where>"

                    System.Data.DataTable dataTable =  web.GetSiteData(siteDataQuery);
                }

I need to search every subsites and their respective document and page libraries.

Any ideas??

Upvotes: 0

Views: 2680

Answers (1)

Sharique Hussain Ansari
Sharique Hussain Ansari

Reputation: 1456

Please use this for document library:-

siteDataQuery.Lists ="< listsLists ServerTemplate=\"101\" />";

SharePoint Server Template Id for

Page Library => 850

and for

Document library => 101

try to use this siteDataQuery.Lists as below

siteDataQuery.Lists = "<Lists MaxListLimit=\"2\">" +
              "<List ID="+web.Lists.TryGetList("firstlistname").ID+" />" +
              "<List ID="+web.Lists.TryGetList("secondlistname").ID+" />" +             
           "</Lists>";

Hope this will help

Upvotes: 1

Related Questions