XmlSerializer serializer = new XmlSerializer(typeof(TextBox_Input));
FileStream fs = null;
try
{
fs = new FileStream("myxml.xml", FileMode.Create, FileAccess.ReadWrite);
// String fileName = "D:\C#\XmlCe\XmlCe\myxml.xml";
TextWriter writer = new StreamWriter(fs,Encoding.UTF8);
// StringWriter writers = new StringWriter(myxml);
serializer.Serialize(writer, textstring);
writer.Dispose();
}
finally
{
if (fs != null)
fs.Dispose();
}
错误:
msdn:有例子
private void SerializeCollection(string filename){
Employees Emps = new Employees();
// Note that only the collection is serialized -- not the
// CollectionName or any other public property of the class.
Emps.CollectionName = "Employees";
Employee John100 = new Employee("John", "100xxx");
Emps.Add(John100);
XmlSerializer x = new XmlSerializer(typeof(Employees));
TextWriter writer = new StreamWriter(filename);
x.Serialize(writer, Emps);
但是我用了,StreamWriter(filename);vs不接受参数 string类型,接受streaml类型,很困惑,求大神帮忙解答。