我坚持这种愚蠢的形式......继承人我的代码。它将它保存在流编写器想要的位置,但是当我通过保存对话框将它保存在用户想要的位置时,它会创建 XML,但不会在其中放入任何内容!有人可以看一下,因为它开始让我感到震惊!
void SavebuttonClick(object sender, EventArgs e)
{
Stream myStream ;
SaveFileDialog savefile1 = new SaveFileDialog();
savefile1.Filter = "xml files |*.xml" ;
savefile1.FilterIndex = 2 ;
savefile1.RestoreDirectory = true ;
if(savefile1.ShowDialog() == DialogResult.OK)
{
if((myStream = savefile1.OpenFile()) != null)
{
Values v = new Values();
v.task1_name = this.task1_name.Text;
v.task1_desc = this.task1_desc.Text;
v.task1_date = this.task1_date.Value;
v.task1_time = this.task1_time.Value;
SaveValues(v);
}
myStream.Close();
}
}
这是主播...
public void SaveValues(Values v)
{
XmlSerializer serializer = new XmlSerializer(typeof(Values));
using(TextWriter textWriter = new StreamWriter(@"E:\TheFileYouWantToStore.xml"))
{
serializer.Serialize(textWriter, v);
}
...
}
编辑:
public class Values
{
public string task1_name { get; set;}
public string task1_desc { get; set;}
public DateTime task1_date { get; set;}
public DateTime task1_time { get; set;}
}
我想这是你的意思的代码,我对编码相当陌生,虽然 mate :(