本文介绍了如何在XML中插入文本框值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用c#在xml中插入文本框值和日期。
我尝试过:
i已经尝试了我的self.i我是xml的新手所以引导我。
How to insert the textbox value and date in xml using c#.
What I have tried:
i have tried my self.i am new to xml so guide me.
推荐答案
public class MyData
{
public string Name { get; set; }
public DateTime DateValue { get; set; }
}
并将其序列化为xml
and serialize it to an xml as
MyData obj = new MyData();
obj.Name = txtBox.Text;
obj.DateValue = DateTime.Now;
string path = Server.MapPath("myFile.xml");
XmlSerializer serializer = new XmlSerializer(typeof(MyData));
using (TextWriter writer = new StreamWriter(path))
{
serializer.Serialize(writer, obj);
}
这篇关于如何在XML中插入文本框值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!