这段代码的功能是想导出一个XML文档,但是运行到DevDataShareXml.XmlRWFun.ObjToXmlFile("config.xml", r);的时候try里面出现异常,请问应该怎样写可以实现功能??
public static void test()
{
celledit1 r = new celledit1();
r.MenuName = "窗口显示配置表";
r.listnum = 2;
r.s = new celledit[] {
new celledit("listname1", "轴号", "textbox"),
new celledit("listname2", "轮对编号", "combox") };
DevDataShareXml.XmlRWFun.ObjToXmlFile("config.xml", r); } public class celledit1
{
public string MenuName;
public int listnum;
public celledit[] s;
}
public class celledit
{
public string Listname;
public string name;
public string edit;
public celledit(string Listname,string name ,string edit)
{
this.Listname = Listname;
this.name = name;
this.edit = edit;
}
}
public static bool ObjToXmlFile(string filename,object value )
{
try
{
XmlSerializer serializer = new XmlSerializer(value.GetType());
Stream writer = new FileStream(filename, FileMode.Create);
serializer.Serialize(writer, value);
writer.Close();
writer.Dispose();
return true;
}
catch (System.Exception ex)
{
}
return false;
}
public static void test()
{
celledit1 r = new celledit1();
r.MenuName = "窗口显示配置表";
r.listnum = 2;
r.s = new celledit[] {
new celledit("listname1", "轴号", "textbox"),
new celledit("listname2", "轮对编号", "combox") };
DevDataShareXml.XmlRWFun.ObjToXmlFile("config.xml", r); } public class celledit1
{
public string MenuName;
public int listnum;
public celledit[] s;
}
public class celledit
{
public string Listname;
public string name;
public string edit;
public celledit(string Listname,string name ,string edit)
{
this.Listname = Listname;
this.name = name;
this.edit = edit;
}
}
public static bool ObjToXmlFile(string filename,object value )
{
try
{
XmlSerializer serializer = new XmlSerializer(value.GetType());
Stream writer = new FileStream(filename, FileMode.Create);
serializer.Serialize(writer, value);
writer.Close();
writer.Dispose();
return true;
}
catch (System.Exception ex)
{
}
return false;
}
解决方案 »
- 一个数组的打印
- 弱弱的问下.安装 net framework 2.0 sp2 之前要不要先装 net framework 2.0?
- 请问各位大牛这句话如何理解“C#引用类型存储对值得引用”
- C#基础语法疑问
- Array.BinarySearch 和 Array.IndexOf
- c#获取窗口焦点问题
- ODBC数据源配置测试成功,但是程序不能连接SQLServer
- 添加的问题
- Winform下算吧,有含金量的题,解了却感觉怪怪的.评评,或许有更高效的
- 简单的编码转换问题,高分相送
- 请教各位大侠,winform下webbrower.url.tostring();之后乱码的问题
- 自动生成那个label
Stream writer = new FileStream(filename, FileMode.Create);
也没仔细看,你的ObjToXmlFile方法中获取的filename只是config.xml,我不知道没有完整的路径这个东西会存到哪去。。