Tuesday, December 6, 2011

Export DataSet to XML File

create xml file from a dataset
This code snippet show how to export DataSet to xml file.Here we have taken data from database and fill dataset.We have taken a aspx page and a button there,after clicking the button a xml file will be created at specified location.

 public void CreateXml()  
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("usp_GetAddressDetails",con);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
StreamWriter objStreamWriter = new StreamWriter("E:\\Santosh\\Practices\\ASP\\XMLFiles\\EmpAddress.xml", false);
ds.WriteXml(objStreamWriter);
objStreamWriter.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
CreateXml();
}


Regards
Santosh Singh

17 comments:

  1. very nice article. its very useful

    You can submit your .net related article links on http://www.dotnettechy.com to get more traffic

    ReplyDelete
  2. Nice effort, very informative, this will help me to complete my task. Thanks for sharing it. Have a look at the process blogs to see more..............Please contact us for Oracle Fusion Financials training details in our Erptree Training Institute

    ReplyDelete
  3. I would like to appreciate your work for good accuracy and got informative knowledge from here.......................Please contact us to know More Information about Oracle HRMS Training

    ReplyDelete
  4. It is really very helpful for us and I have gathered some important information from this blog. For More Information about Oracle Fusion SCM Training related courses please visit our website.

    ReplyDelete