Click here to Skip to main content
15,844,387 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am developing a web application using C# .net, can you give me some idea on how to store data from textbox to XML file in asp.net, like when user enters some data into the textbox's and click's on the submit button, all the data which the user entered into the textbox's should be stored in the XML file.
Posted

 
Share this answer
 
Comments
Monjurul Habib 9-Jul-11 5:17am    
nice link, my 5.
mhamad zarif 9-Jul-11 5:57am    
very nice link, my 5.
Abhinav S 10-Jul-11 1:21am    
As simple as that - 5.
Try to bind XML file to your Textbox value for Saving Data.
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("YourXMLFile"));
ds.Tables[0].Rows[0]["NodeName"] =textbox1.Text; 
ds.AcceptChanges();
ds.WriteXml(Server.MapPath("YourXMLFile"));
 
Share this answer
 
Comments
Sachin__Sharma 9-Jul-11 6:28am    
my +5 good answer.
RaviRanjanKr 9-Jul-11 6:30am    
Thanks Sachin.
You can persist (store and load to/from file/stream/string) data structure of any complexity without any special XML-related effort using Data Contract. You should better prefer it to any other serialization method due to its data-driven matter, lack of intrusive programming, good support of compatibility, support of world-unique schema and ease of use.

Please see: http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

See my past answer where I advocate this great approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating a property files...[^].

—SA
 
Share this answer
 
Comments
Abhinav S 10-Jul-11 1:21am    
Good answer. My 5.
Sergey Alexandrovich Kryukov 10-Jul-11 1:30am    
Thank you, Abhinav.
--SA
 
Share this answer
 
Try the following simple code :

public String s = Server.mappath( "\\Titles.xml");

XmlTextWriter writer = new XmlTextWriter(s, null);
               writer.WriteStartElement("menu");
               writer.WriteStartElement("buttons");
               writer.WriteStartElement("button");
               writer.WriteElementString("label", textBox1.Text);

               writer.WriteEndElement();
               writer.WriteEndElement();
               writer.WriteEndElement();
               writer.Close();


Where s is the name of your xml file that is you have.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900