执行代码时收到的错误是:'ArgumentException未处理。路径中包含非法字符。”

我正在使用以下代码访问我的.xml文件。

string appPath = Path.GetDirectoryName(System.Environment.CommandLine);
FileInfo fi = new FileInfo(appPath + @"\Books.xml");


我这样做是针对控制台应用程序,而不是WinForm。一段时间以来,我一直在详尽搜索和搜索SO。

这是一项家庭作业项目的一部分。但是,这是我遇到的唯一问题。

最佳答案

string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
FileInfo fi = new FileInfo(Path.Combine(appPath, "Books.xml"));

10-07 23:11