Downloading List Items from a share point list using share point list web service from an application
The share point is one of the most widely used technologies and most of the projects use it for management of documents and other things. Share point has all the things built in which the user needs to configure and use.
There are few scenarios where your application might need to download the List Items which were stored in a share point and process it in your application. In this example we will discuss how to download a share point list item using the share point list web service.
Hoping that all the pre requisites are met like having access to share point list and the entire development environment is set up. I am directly jumping in to the coding part.
The first thing we need to do is add the web reference of the share point list service to our application (web or windows based). By default share point provides the web service and in share point 2010 we have WCF service. The share point list service would be like this
1. Add this as a web reference
Then the code to download is as follows:-
using ApplicationName.SharePointListName;
public void GetSharePointListItems()
{
XmlDocument xmlDoc = new XmlDocument();
XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>";
SharepointService.Lists listService = new SharepointService.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode xmlListItems = listService.GetListItems("ListName", String.Empty, null, null, null, ndQueryOptions, null);
DataSet dsList = new DataSet();
XmlTextReader xmlTxtReader = new XmlTextReader(xmlListItems.InnerXml, XmlNodeType.Element, null);
dsList.ReadXml(xmlTxtReader);
System.Data.DataTable datatable = dsList.Tables[1];
}
The data is available only in the Tables[1] and not in Tables[0];
No comments:
Post a Comment