将数据从TextBox保存到XML文件 [英] Save data from TextBox into XML File

查看:81
本文介绍了将数据从TextBox保存到XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我正在使用C#.net开发一个Web应用程序,能否给我一些有关如何将文本框中的数据存储到asp.net中的XML文件的想法,例如当用户在文本框中输入一些数据并单击

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.

推荐答案


尝试将XML文件绑定到文本框"值以保存数据.
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"));


您可以使用 Data Contract持久保存任何复杂性的数据结构(从文件/流/字符串加载/从文件/流/字符串加载/从文件/流/字符串加载/到文件/流/字符串).我>.由于它的数据驱动问题,缺乏介入式编程,对兼容性的良好支持,对世界唯一模式的支持以及易于使用,因此您最好比其他任何序列化方法都更喜欢它.

请参阅:
http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

在我倡导这种出色方法的地方,请参阅我过去的回答:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [
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


这篇关于将数据从TextBox保存到XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆