【发布时间】:2014-08-06 14:38:51
【问题描述】:
我正在尝试打开一个动态创建的 xml 文件。这是我将文件写入磁盘的代码,然后立即读取它。
string filename = "/Files/Runs/" + LoginServer.CurrentUsername + "/NEMSIS/" + SaveDestination + ".xml";
y.WriteToFile(filename);
System.Diagnostics.Process.Start(filename);
编写代码:
// Write an EMSDataset to file
public void WriteToFile(string filename)
{
var Ser = new XmlSerializer(typeof(EMSDataSet));
using (StreamWriter Sw = new StreamWriter(filename))
Ser.Serialize(Sw, _nemsisDocument);
}
错误信息:
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
Additional information: The system cannot find the file specified
If there is a handler for this exception, the program may be safely continued.
是什么导致了这个异常?文件名完全相同,但我无法阅读文档。该文件已创建(我可以在 Windows 资源管理器中导航到它)。 Process.Start() 是否在其他位置搜索?
【问题讨论】:
-
如果您在 Windows 资源管理器中双击该文件,它会打开吗?
-
是的。 200 多行 xml。
-
尝试完全限定文件路径,而不是相对于您当前的工作目录进行。 System.Diagnostics.Process.Start 可能在不同的位置启动。
-
@Matt,但它打开的是什么?
标签: c# xml file exception filesystems