More SharePoint List Web Service Calls
In this post I showed how the SharePoint Web Services can be used to get a list of the lists in a SharePoint site. The code in this post shows how, once you have the GUID associated with a list, you can then retreive all the items from the list.
The method ‘FillListItems’ is passed the GUID for a SharePoint list and returns the list of items in the SharePoint list:
public void FillListItems(Guid g)
{
XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(“<root/>”);
XmlNode listQuery = doc.SelectSingleNode(“//Query”);
XmlNode listViewFields = doc.SelectSingleNode(“//ViewFields”);
XmlNode listQueryOptions = doc.SelectSingleNode(“//QueryOptions”);
XmlNode items = lst.GetListItems(g.ToString(), string.Empty,
listQuery, listViewFields,
string.Empty, listQueryOptions, null);
The Web Service method “GetListItems” can be used to return items from a list based on a list selection (‘listQuery’), a field selection (‘listViewFields’) and a list of options (‘listQueryOptions’). In this case all fields and all items are returned. The method returns a XmlNode list containing the items and the fields for these items. Each item is returned as a row element with the fields returned as attributes:
<rs:data ItemCount=“1“ xmlns:rs=“urn:schemas-microsoft-com:rowset“>
<z:row ows_Attachments=“0“
ows_LinkTitle=“Get Started with Windows SharePoint Services!“
ows_Modified=“2007-07-13 11:50:10“
ows_MetaInfo=“1;#“
ows__ModerationStatus=“0“
ows__Level=“1“
ows_Title=“Get Started with Windows SharePoint Services!“
ows_ID=“1“ ows_owshiddenversion=“1“
ows_UniqueId=“1;#{2B29357D-4861-4FE2-A2A2-D6EF549867EE}“
ows_FSObjType=“1;#0“
ows_Created_x0020_Date=“1;#2007-07-13 11:50:10“
ows_Created=“2007-07-13 11:50:10“
ows_FileLeafRef=“1;#1_.000“
ows_FileRef=“1;#sites/Intranet/ProjectX/Lists/Announcements/1_.000“
xmlns:z=“#RowsetSchema“ />
</rs:data>
Because SharePoint 2007 allows a list to contain items with different content types, the items in a list may have different fields.
For a demo web part page that uses the Data View to access this web service, see
http://www.wssdemo.com/pages/lists.aspx
Select any list on the left to get the list and field details on the right.
Ian Morrish
July 14, 2007 at 8:32 pm
Ian, thanks for the link – the demo looks very good. Nick
nickgrattan
July 16, 2007 at 11:58 am
It was very use full
Haf
October 22, 2008 at 9:50 am