One common tasks that I have needed to do while working with SharePoint 2007 (MOSS) is to retrieve information in regards lists or libraries. You need this information when you want to perform add, update, or delete functions when working with data from a document library.
In today's post I will walk you though retrieving the list information. We will be getting this list information via the Lists.asmx web service.
Like I said above, this is a common task for me, so I have made this a utility style method. You will notice that I pass in 2 different parameters into this method. The first one is an enumeration value that contain the names of my different sites/sub-sites. The second one is the name of the document library that I an want to work with.
Code to pull out the list information:
Code below is called by the code above to build us a valid instance of the web service. This method here is public because it is actually part of another class. The Lists return type is an instance of the Webservice object.
Code Explained
- First thing we need to do is build a connection to the web service
- Once we have our web service instance we need to connect to the service via the GetLists method. This will return an XmlNode object for use.
- After we have the XmlNode return value from the GetList method we need to pull out the ID and Version values. To take a look at all the possible values/data that is returned via the GetList method simply do a listResponse.OuterXml call on the listResponse XmlNode.
- Lastly we build an instance of my ListDataInformation object. This object is a simple object with 3 properties that hold the ID, name and version.
Here you have it, a pretty simple and straight forward way to retrieve different information about your Sharepoint List.
Till next time,