0

I am calling GetListItems via c# code to return all items in a SharePoint list. Here is a snippet of code:

private string listName = "Test2";
private string viewName = string.Empty;
private string rowLimit = "150";


SPListService.Lists listService = new SPListService.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
listService.Url = "http://test.testsite.sp/MyTest/_vti_bin/Lists.asmx";

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement query = xmlDoc.CreateElement("Query");
System.Xml.XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
System.Xml.XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");

query.InnerXml = "";
viewFields.InnerXml = "<FieldRef Name=\"Title\" />";
queryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc> ";

System.Xml.XmlNode nodeListItems = listService.GetListItems
(listName, viewName, query, viewFields, rowLimit, queryOptions, null);

I do not get an error but no results are returned.

InnerXml    "\n<rs:data ItemCount=\"0\" xmlns:rs=\"urn:schemas-microsoft-com:rowset\">\n</rs:data>\n"

I have searched various sites (including this one) and nothing seems to work. :-(

I have also tried to pass in GUIDs for the viewName and listName, but makes no difference.

Has anyone else been through this before?

I am starting to wonder whether it's the permissions on the SharePoint side that could be causing this.

Thank you

  • Did you copy this code directly from your source? The line queryOptions.InnerXml = "IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc> "; is missing a < before IncludeMandatoryColumns – Jeff Freeman Aug 30 '17 at 18:47
  • Hi Jeff, thanks for pointing this out, I have included the < before IncludeMandatoryColumns in the actual code. I will amend this in the post now. – hungryhorse Aug 30 '17 at 20:04
0

You need to add a "Query". Try:

query.InnerXML = "<Where><IsNotNull><FieldRef Name='ID'/></IsNotNull></Where>";

This should return "All Items". If you want to filter it, you'll need to learn the specific CAML query needed for that.

  • Hi Chad, thanks for you'r reply. Unfortunately that didn't change anything, I'm still not getting anything back. – hungryhorse Aug 31 '17 at 7:34
  • Interesting, ok I looked at my code and noticed a couple other things. Instead of empty string try null for the view name. Instead of list name, try list ID (internal GUID), you can get this from the List Settings page in the url. Remove the extra space at the end of QueryOptions. Everything else looks good unless my eyes aren't catching a typo. – Chad Aug 31 '17 at 15:02
  • Forgot one other thing. Try query.InnerXml = "<IsNotNull><FieldRef Name='ID'/></IsNotNull>"; (basically remove the Where portion). – Chad Aug 31 '17 at 15:07

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.