Last post Aug 26, 2011 09:25 PM by Prateek Joshi
Sep 11, 2009 08:58 AM|engg_mahesh_knl|LINK
I wants to Create XML file Dynamically Using ASP.Net C# On Server through which
i can create / delete xml file Using SQL Server Database on Server Dynamically...
Plzz Answer me ... Im very much puzzelled.....
Sep 11, 2009 09:57 AM|abhijeet_dighe|LINK
1. Fill up dataset with query result:
2. Then create XmlDataDocument with dataset:
XmlDataDocument xmlDoc = new XmlDataDocument(ds);
3. Finally you can save XmlDataDocument as xml file on server:
Sep 11, 2009 10:01 AM|kavita_khandhadia|LINK
Go through my Blog Post, where I have demonstarted a runnable code for the same
Usig xmlDom you can create xml like this-
From dataBase tou can create like this
If you have any sample XML , which you want to generate , Then let me know. I could write a example from it for you.
Sep 11, 2009 11:12 AM|engg_mahesh_knl|LINK
Actually I wants to store simple data of employee into xml file i.e at the time when user log in then an xml file will automatically generated....and after user logouts this file will be deleted...plzz solve this problem....
Sep 11, 2009 11:25 AM|kavita_khandhadia|LINK
Code in aspx
<asp:TextBox runat="server" ID="txtFirstName" Text="Kavita"></asp:TextBox>
<asp:TextBox runat="server" ID="txtLastName" Text="Khandhadia"></asp:TextBox></td>
Code in aspx.cs
string strMyXml = "<Employee>"+
XmlDocument xDoc = new XmlDocument();
//Here the xml is prepared and loaded in xml DOM.
xDoc.Save(Server.MapPath("myNewXmlPerson.xml"));//instead of myNewXmlPerson , u can give any name.
//The above line will save your XML.
//This is one way to create xml. This method may not be very efficient to manage 500 data
//You can go for using XmlDom instead to create xmlNodes.] Let me know if you want follow
//xmlDom approach. To see its example you can read my blog post at
//Now if u want to read this xml and get data from it and assign their value to text box you can do like this
txtFirstName.Text = "";
txtLastName.Text = "";
XmlDocument xDocRead = new XmlDocument();//I have taken this new object for your better understanding.
XmlNode xFN = xDocRead.SelectSingleNode("Employee/firstName");
XmlNode xLN = xDocRead.SelectSingleNode("Employee/lastName");
txtFirstName.Text = xFN.InnerText;
txtLastName.Text = xLN.InnerText;
Let me know if the above example works for you, if you have any dobt let me know.
Sep 11, 2009 11:34 AM|engg_mahesh_knl|LINK
in plcae of following code...tell me if i dont wants to fetch data statically but i wants to fetch data from database and after that store it into string..I am trying it by using dataset but but it is showing error...plzz tell me if you can..
string strMyXml = "<Employee>"+
thanks for previous code...
Sep 11, 2009 11:51 AM|engg_mahesh_knl|LINK
in place of following code...tell me if i dont wants to fetch data statically but i wants to fetch data from database to XMl File and after that store it into string..I am trying it by using dataset but but it is showing error...plzz tell me if you can..
string strMyXml = ""+ ""+txtFirstName.Text+""+ ""+txtLastName.Text+""+ ""; thanks for previous code... /p>
Sep 11, 2009 12:17 PM|kavita_khandhadia|LINK
How do you fetch data from database and where do you keep it in your code behinde in some datatable? if yes then let me know the structure of the dataTable.
Sep 11, 2009 12:28 PM|engg_mahesh_knl|LINK
i have Solved database Problem....
Now plzz tell me that how can I Delete the same file from server by clicking on button..
Sep 11, 2009 12:51 PM|kavita_khandhadia|LINK
Write the following method. And then pass the xml file name along with the path. It will be removed.
public void RemoveFile(string path)
if (path != "")
FileInfo fileInfo = null;
fileInfo = new FileInfo(path);
catch (Exception ex)
throw new Exception(ex.Message);
Sep 12, 2009 05:21 AM|engg_mahesh_knl|LINK
Hii Ms. Kavita....Thankyou for solving my problem..........
I have marked your answer as the right answer.........I wants your help again...
Plzz solve my another problem.....
I m describing you my problem..........I have one xml file named as "xmlFile.xml" and working it with asp.net file "default.aspx"....when i writing data into database to my xml file it overwrites value all the time when i executes my program...
I wants that when i changes my SQL Query then after execution it dont overwrites the xml file but it attach the new contents to it ....through by my old data also be saved ....
I am sending you my code....Tell me If i change name=rahul to name=mahesh....then the xmlfile.xml...dont overwites the whole file....rather than this it Writes the new code with the old searched result.....
SqlConnection con = new SqlConnection("Data Source=aa-55e363721674\\SQLEXPRESS;Initial Catalog=test;Integrated Security=True;Pooling=False");
DataSet ds = new DataSet();
//SqlDataReader dr = new SqlDataReader();
SqlDataAdapter adp = new SqlDataAdapter("select * from emp_test where name='Rahul'", con);
string XMLFile1 = Server.MapPath("XMLFile.xml");
// Use WriteXml to write the document.
DataSet ds1 = new DataSet();
ds.ReadXml(Request.PhysicalApplicationPath + "XMLFile.xml");
GridView1.DataSource = ds;
GridView1.AllowPaging = true;
GridView1.PageSize = 6;
Thankyou in Advance
Oct 05, 2009 06:40 AM|sach.chopade15|LINK
i want to genrate a xml file and bind xml to treeview structure in asp.net.
in my sql database i am having string like
how can be the xml created
can u please help me..
thanks in advance
Oct 05, 2009 08:52 AM|kavita_khandhadia|LINK
I think this question is not entirely related to this thread.. can you create a new thread for it.. till then let me have alook at your problem...
Apr 06, 2010 01:50 PM|sach.chopade15|LINK
Hi Kavita, have u find the solution for it?? waiting for you reply Thanks for considering the question! :)
Jul 26, 2010 04:49 AM|JBhushan|LINK
Hi, Bhushan here. Thank u... Your post really worked for me... regarding the creation of Dynamic xml file...
But now... I wanted to Ask u, can we query the xml file as we query on sql Server database using where clause and likes?
Jul 26, 2010 05:48 AM|kavita_khandhadia|LINK
yes we can..query the file using xPaths and objects in system.xml ...also if u are using 3.5 then u can use LINQ.
Aug 26, 2011 09:25 PM|Prateek Joshi|LINK
It worked for me.