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.
}
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