Reputation: 3044
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'.'
How can I get it to pass into the load function?
Upvotes: 0
Views: 856
Reputation: 222682
Use Server.MapPath
to get the path to your file
Server.MapPath("~/App_Data/makes.xml")
Upvotes: 3