---
title: "Create XML file from Dataset in C#"  
description: "Create XML file from Dataset in C#"  
author: "Anonymous User"  
published: 2013-06-15  
updated: 2013-07-08  
canonical: https://www.mindstick.com/forum/1171/create-xml-file-from-dataset-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Create XML file from Dataset in C#

Hi [Developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs),\

How can I create a [XML file](https://www.mindstick.com/forum/360/how-to-read-xml-file-in-php) from [Dataset](https://www.mindstick.com/articles/19/dataset) in C#?

## Replies

### Reply by Vijay Shukla

Hi Goti,You can use this code:\

```
using System;using System.Data;using System.Windows.Forms;using System.Xml;  namespace WindowsApplication1{    public partial class Form1 : Form    {        DataTable dt;         public Form1()        {            InitializeComponent();        }         private void button1_Click(object sender, EventArgs e)        {            DataSet ds = new DataSet();            dt = new DataTable();            dt.Columns.Add(new DataColumn("Product_ID", Type.GetType("System.Int32")));            dt.Columns.Add(new DataColumn("Product_Name", Type.GetType("System.String")));            dt.Columns.Add(new DataColumn("product_Price", Type.GetType("System.Int32")));            fillRows(1, "product1", 1111);            fillRows(2, "product2", 2222);            fillRows(3, "product3", 3333);            fillRows(4, "product4", 4444);            ds.Tables.Add(dt);            ds.Tables[0].TableName = "product";            ds.WriteXml("Product.xml");            MessageBox.Show("Done");        }         private void fillRows(int pID, string pName, int pPrice)        {            DataRow dr;            dr = dt.NewRow();            dr["Product_ID"] = pID;            dr["Product_Name"] = pName;            dr["product_Price"] = pPrice;            dt.Rows.Add(dr);        }    }}
```


---

Original Source: https://www.mindstick.com/forum/1171/create-xml-file-from-dataset-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
