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?

  • According to the msdn article (msdn.microsoft.com/en-us/library/…), you have done it right. Try to verify the 'listId' parameter, it should be the list Guid without '{' and '}'. – KhalilG Mar 18 '15 at 13:19
  • @KGahbiche I replaced Lists parameter to "<Lists><List ID=\"" + lib.Id.ToString("D").ToUpper() + "\"/></Lists>". Result Lists string is: "<Lists><List ID="9027A315-0B24-4278-BC54-8C6D6BBC8C85"/></Lists>". I've checked list, it has same id and there is one task in this list. But result is still empty. – asolovyov Mar 18 '15 at 13:26

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

query.ViewFields = "<FieldRef Name='Title' Nullable='True'/>";
  • If it was the reason of my problem, first query with ServerTemplate condition should be empty too, but it returns valid data. – asolovyov Mar 18 '15 at 13:30
  • I've checked your solution and It works, but I don't understand why first request returns values with same fields... Thanks! – asolovyov Mar 18 '15 at 13:33
  • @Amal, Could you please explain us the problem and the solution ? Thanks. – KhalilG Mar 18 '15 at 13:36
  • @KGahbiche If I understand it right, Nullable attrubute should be set to True if some fields in result can be empty. – asolovyov Mar 18 '15 at 13:40
  • @KGahbiche If the field contains NULL values, then instead of Skipping it returns empty. This information I found based on my experience with SPSiteDataQuery – Amal Hashim Mar 18 '15 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.