I am having an xml file in my application root directory. I need to load this xml file into a dataset in asp.net 4.0
Please provide me with the coding
Regards,
RAJAN CRP
DataSet ds = new DataSet();
myURL =Server.MapPath("XMLFile17.xml");
ds.ReadXml(myURL);
Refer:
http://forums.asp.net/t/1468913.aspx/2/10
Hi,
You can use below code,
using System;
using System.Data;
using System.Data.SqlClient;
pubic DataSet ReadXmlFile()
{
String filename;
filename = Server.MapPath("/MyWebSite/"+filename);
DataSet ds = new DataSet();
// Create new FileStream with which to read the schema.
System.IO.FileStream fsReadXml = new System.IO.FileStream
(filename, System.IO.FileMode.Open);
try
{
ds.ReadXml(fsReadXml);
return ds;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return null;
}
finally
{
fsReadXml.Close();
}
}
Hope this helps!
沒有留言:
張貼留言