Friday, October 12, 2012

How to read XML file data in sharepoint 2010

 
In this post i have given code for how to read  the XML file data which in document library .Here i instantiated a Web Request object by using the path(URI) of the XML file ,then get the Response from path using Web Response class.The GetResponseStream method  is used to get the stream of  content in XML file to stream.Finally we will read the stream into resultant string.By doing the same process we can access any external XML file(URI) into application.But we have to use HttpwebRequest class to make request.
String file_path = "http://sp12/test"
WebRequest wr = WebRequest.Create(file_path);
wr.Credentials = CredentialCache.DefaultCredentials;
WebResponse Wresponse = wr.GetResponse();
using (StreamReader str = new StreamReader(Wresponse.GetResponseStream()))
{
String Result_Data =str.ReadToEnd();
}
Response.Close();

No comments:

Bel