Question

When I am querying lists items via SPSiteDataQuery by ServerTemplate, it returns items:

SPSiteDataQuery query = new SPSiteDataQuery();
query.Lists = "<Lists ServerTemplate=\"107\"/>";
query.ViewFields = "<FieldRef Name=\"Title\"/>";
query.Query = "<OrderBy><FieldRef Name=\"Title\"/>";
query.Webs = "<Webs Scope=\"SiteCollection\"/>";

DataTable dt = web.GetSiteData(query);

But when I replace Lists condition to "<Lists><List ID=\"" + listId + "\" /></Lists>" it returns empty datatable.

listId is correct, List exists in child site of web.

Where I am wrong?

Was it helpful?

Solution

On possible issue is with Null Values in the Title field. So try changing ViewFields as follows

query.ViewFields = "<FieldRef Name='Title' Nullable='True'/>";
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top