Showing posts with label Programming SharePoint 2007 Web Services. Show all posts
Showing posts with label Programming SharePoint 2007 Web Services. Show all posts

Monday, November 9, 2009

Programming SharePoint 2007 Web Services

Programming SharePoint 2007 Web Services

In the below example we will see how to get list items from a SharePoint list using SharePoint built in web services.
1. Open Visual Studio 2005
2. Create a new web application/web site of your choice, give the name MossWebServiceExample.
3. Add Web reference - either you can choose web services from local machine or by specifying the url http://servername:portnumber/_vti_bin/Lists.asmx - give the name ListService to the added web reference
4. Wihtin the page class file add a reference to the added web service
using MossWebServiceExample.ListService;

use the below code and you are done

ListService.Lists listService = new Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");

ndViewFields.InnerXml ="";
ndQuery.InnerXml = "Specify text;

try
{
XmlNode ndListItems =
listService.GetListItems("", null, ndQuery, ndViewFields, "", null, null);
Page.Response.Write(ndListItems.InnerXml);
}

catch (System.Web.Services.Protocols.SoapException ex)
{
Page.Response.Write("Message:\n" + ex.Message + "\nDetail:\n" + ex.Detail.InnerText + "\nStackTrace:\n" + ex.StackTrace);
}