Get list data using listdata.svc in SharePoint 2010

listdata.svc is a WCF service which is used for accessing SharePoint 2010 list data with output as an xml.

Below is code that you can use :

//Get the Url of the REST service

String ServiceUrl = SPWebUrl + “_vti_bin/listdata.svc/” + httpUtility.UrlEncode (ListName);

// Create Request object

WebRequest request = WebRequest.Create(ServiceUrl);

// Setting up the user Credentials

request.Credentials = CredentialCache.DefaultNetworkCredentials;

// Create Response object

WebResponse response = request.GetResponse();

// Create a XML document to write the response or list data. Note : REST service returns data as Xml.
XmlDocument doc = new XmlDocument();
Using (Stream strm = response.GetResponseStream())
{
doc.Load(strm); // Load list data in doc object.
}

0 comments:

Post a Comment

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at sharepointprogrammingblogger@gmail.com .

Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.

@ Learning SharePoint.com