Thursday, 28 September 2017

How to retrieve data from multiple lists in SharePoint

 SPSiteDataQuery class is used to retrieve data from multiple lists.
It queries the data query that can be performed across multiple lists in multiple web sites in the same web site collection.
 Usually it is used in list aggregation, where list data from team sites or other subsites is collated and presented in a single interface.
- It aggregates the data from SharePoint lists only while ignoring data from external lists. It return a DataTable class which can be used to access the data.

It will only return results from one list type at a time.

SPSiteDataQuery query = new SPSiteDataQuery();
query .ViewFields = “<FieldRef Name=”Title”/>”;
query .Lists = “<Lists ServerTemplate=”101″/>”;
query .Webs = “<Webs Scope=”SiteCollection”/>”;
query .Query = “<Where>” +
“<Contains>” +
“<FieldRef Name=”Title”/>” +
“<Value Type=”Text”>Conditional Parameter </Value>” +
“</Contains>” +
“</Where>”;

SPSite site = new SPSite(http://applicationurl);

SPWeb web = site.OpenWeb();
DataTable dt = web.GetSiteData(query);

dt.Rows[0]["Title"]);



 

Thank you very much

          Fahadullah Karimi

         SharePoint Specialist


SharePoint List Server Template IDsSharePoint Custom Solution/WSP Memory Leak Solution

No comments:

Post a Comment