Monday, July 3, 2017

CSOM - Get list items using SPSiteDataQuery


SPList oList = context.GetWebList(LISTNAME);
Guid listGuid = oList.ID;

SPSiteDataQuery dataQuery = new SPSiteDataQuery();
dataQuery.Webs = "<Webs Scope=\"Recursive\">";
SPQuery query = new SPQuery();
query.Query = string.Format("<Where><And><Eq><FieldRef Name='Title' /><Value Type='Text'>{0}</Value></Eq></Where><OrderBy><FieldRef Name='ID'/></OrderBy>", titleString);

dataQuery.Query = query.Query;
dataQuery.Lists = string.Format("<Lists><List ID=\"{0}\" /></Lists>", listGuid);
dataQuery.ViewFields = "<FieldRef Name=\"Title\" Nullable=\"TRUE\"/>";

DataTable dt = GetResults(dataQuery, "TableName");

No comments:

Post a Comment