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);
}

3 comments:

  1. Hi,

    This artical is very useful for me. I am a Share Point developer and always looking to

    learn something new. I would like to introduce another good SharePoint blog, Have a look.

    http://SharePointBank.com
    Harry

    ReplyDelete
  2. I have heard about another way of recover damaged adobe illustrator files. Besides, you can visit my blogs at: http://daspeac.livejournal.com/ or http://daspeac.blogspot.com/ where I’m trying to share my experience with regard to data corruption issues

    ReplyDelete
  3. Hi,In many ways this is true of any design process - navigation is no way near as sexy as that lovely design look! Supermarkets have traditionally spent a lot of time getting those aisles lined up in Web Design Cochin so that you buy items you don't really need.Thanks..........

    ReplyDelete