• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Lists.GetListItems (MS SharePoint)

I'm writing a C# program which needs to get a list of documents in a specific document library on a SharePoint site. It was previously written to use the DWS web service, calling DWS.GetDwsMetaData and querying into the XML returned. The problem was that this method returns a TooManyItems error in the XML if there are more than 99 elements of the list, and I need to rewrite the program to get around this glitch.

I think the best solution is to use the Lists web service instead. I want to call Lists.GetListItems and have it return exactly the same XML format that the DWS.GetDwsMetaData returned. I'm a complete noob at this, and I'm looking for some help writing the query I'll need to feed into the method call.

Here's the documentation on the method:
http://msdn.microsoft.com/en-u...ists.getlistitems.aspx

Specific questions:
1. How do I create the query element I'm supposed to pass into the method, and what query would I use to get all the contents of a list? (Like a Select * from Documents.)
2. If I set rowLimit to a value greater than 99, will that solve my TooManyItems problem?
3. What exactly is a view, or should I just ignore it since it's an optional parameter?
4. How can I find the GUID for a list, given the URL to the SharePoint, URL to the document library within the SharePoint, and knowing that the list's name="Documents"?

Sorry if this is a really loaded question. Any help would be appreciated.

- Jen
 
1. You'll create a CAML query. The easiest way to get all list items is to pass just an OrderBy element, like this: <Query><OrderBy><FieldRef Name="ID" Ascending="True"/></OrderBy></Query>. Be sure that you pass in view fields for everything you need returned, otherwise they won't be included in the response.
2. I don't think you'll want to set a rowLimit. I work with the API much more than the web services, so this could be wrong and you may have to supply a very large number (ex. Int32.MaxValue)
3. Lists of data can be displayed in a variety of ways. Views are just different presentations of the data with different fields/sorts/filters/groupings. You'll probably just want to use the default view, so pass in an empty string.
4. You can get the GUID by visiting the list in a browser, clicking on Settings -> Document Library Settings. You'll see the URL encoded GUID in the querystring. Alternatively, you can do this through the API in an application with the attached code. The code would have to be run on the SharePoint server.
 
Hi, thanks for the reply. I tried your suggestions, but I'm still confused about a couple things:

1. The web service returns quite a few more fields than I specify. Also, if I leave viewFields blank, it seems to return all fields. I guess this isn't a problem; just thought I'd point it out.
2. If there are any subfolders in the Documents list, it will return those folders and their ID's, but if I try to call the web service again using those ID's, I get a "list not found" error. How can I recursively search the contents of each subfolder?

Thanks!!!
 
Originally posted by: Jen53403
Hi, thanks for the reply. I tried your suggestions, but I'm still confused about a couple things:

1. The web service returns quite a few more fields than I specify. Also, if I leave viewFields blank, it seems to return all fields. I guess this isn't a problem; just thought I'd point it out.
2. If there are any subfolders in the Documents list, it will return those folders and their ID's, but if I try to call the web service again using those ID's, I get a "list not found" error. How can I recursively search the contents of each subfolder?

Thanks!!!

1. I don't know why SharePoint is adding all of those extra fields. Even when specifying <IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns> in the query options, it still returns the fields.

2. You can actually do this all in one query, if you don't need to return the folders themselves. Include this in your query options: <ViewAttributes Scope='Recursive' />
 
Like joshsquall I too am more familiar with using the API to get SharePoint data so I could write pretty quick in C# what you want done, but if you're looking for returning the same XML as before I guess I'm not too much of a help. 😛 I think I will be using the UserProfile WebService here in the near future though.
 
Back
Top