# Example of Inserting and Retrieving data from xml file

**URL:** <https://forum.kirupa.com/t/example-of-inserting-and-retrieving-data-from-xml-file/240118>\
**Category:** programming\
**Created:** [September 29, 2007, 9:24am UTC](https://forum.kirupa.com/t/example-of-inserting-and-retrieving-data-from-xml-file/240118 "2007-09-29T09:24:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hanusoft](https://avatars.discourse-cdn.com/v4/letter/h/d6d6ee/32.png) [@hanusoft](https://forum.kirupa.com/u/hanusoft)\
**Post date:** [September 29, 2007, 9:24am UTC](https://forum.kirupa.com/t/example-of-inserting-and-retrieving-data-from-xml-file/240118/1 "2007-09-29T09:24:26Z")

</div>

This is an example of Inserting and Retrieving data from xml file.

> **[Managed Services Consultants | Hanu Software Solutions, Inc.](https://hanusoftware.com/)**
>
> Hanu helps all types of customers by accelerating innovation with truly custom Azure-based cloud services. Contact Us Today to Learn More.

private void Page\_Load(object sender, System.EventArgs e)  
{  
// Put user code to initialize the page here

```
        if(!IsPostBack)
        {
            BindGrid();
        }
    }

```

private void BindGrid()  
{  
ds = new DataSet();  
try  
{  
ds.ReadXml(@“c:\inetpub\wwwroot\WebApplication10\XMLFile1.xml”);  
DataGrid1.DataSource = ds;  
DataGrid1.DataBind();  
}  
catch(Exception ex)  
{  
throw ex;  
}  
}

```
private void Button1_Click(object sender, System.EventArgs e)
    {
        ds = new DataSet();
        try
        {
            ds.ReadXml(@"c:\inetpub\wwwroot\WebApplication10\XMLFile1.xml");
            DataRow row = ds.Tables[0].NewRow();
            row["name"]=txtName.Text;
            row["fathersname"]=txtFName.Text;
            row["address"]=txtAddress.Text;
            ds.Tables[0].Rows.Add(row);
            ds.WriteXml(@"c:\inetpub\wwwroot\WebApplication10\XMLFile1.xml");
            txtAddress.Text="";
            txtFName.Text="";
            txtName.Text ="";
            BindGrid();
        }
        catch(Exception ex)
        {
            throw ex;
        }
```
