[英]C# XDocument.Load could not find file?
I have the following logic in a controller 我在控制器中具有以下逻辑
public void Makes() {
// iterate over makes.xml
XDocument myDoc = XDocument.Load("makes.xml");
var make = myDoc.Descendants("make");
List<string> list = new List<string>();
foreach (var item in make)
{
Console.WriteLine(item);
}
}
And I get the following error 我得到以下错误
System.IO.FileNotFoundException: 'Could not find file 'C:\\Program Files (x86)\\IIS Express\\makes.xml'.'
System.IO.FileNotFoundException:'找不到文件'C:\\ Program Files(x86)\\ IIS Express \\ makes.xml'。
I have the needed file here: 我在这里有所需的文件:
How can I get it to pass into the load function? 如何获得传递给加载功能的信息?
使用Server.MapPath
获取文件的路径
Server.MapPath("~/App_Data/makes.xml")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.