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

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...