0

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??

user388969
  • 337
  • 1
  • 9
  • 30
  • you can use like this `siteDataQuery.Lists = “”;` where `0f9021b0-77b5-4460-bf5f-b568ae194a00` & `0g9025b0-76b5-4680-bf5f-b568ae191b00` is your list guid, these guid is just an example, see my code. – Sharique Ansari Apr 25 '16 at 19:43

1 Answers1

1

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

Sharique Ansari
  • 1,458
  • 1
  • 12
  • 22
  • can i specify two list templates in one CAML query. I want to search in pages librarires and document libraries once – user388969 Apr 25 '16 at 18:47
  • It's not two lists but can i put to lists template ID here. I will have 3 or 4 document libraries with different names and one or more page libraries too. My idea was to get every items of a content type from all the lists and libraries if present from each sub site. – user388969 Apr 25 '16 at 20:22
  • You can specify any no of list, just change MaxListLimit=4 & in query append the list info as I have written for two lists – Sharique Ansari Apr 25 '16 at 20:41
  • If you want to get all list of a specific content type, try this SPSiteDataQuery query = new SPSiteDataQuery(); query.Webs = ""; query.Lists = ""; query.Query = "" + "0x0101006d76968475dd473f92fbdec03bbff85e" + ""; – Sharique Ansari Apr 25 '16 at 20:46
  • Replace content type id with your content type id. – Sharique Ansari Apr 25 '16 at 20:53
  • The best way was adding the base template for the lists only query.Lists = "" This will search for all the list whose base type is 1 and pages and document libraries have same base type 1 – user388969 Apr 27 '16 at 17:24
  • @user388969 check my comment that is what i had mentioned, probably you missed. – Sharique Ansari Apr 27 '16 at 18:16