XDocument: Could not find file 'C:\Program Files (x86)\IIS Express\myfile

Here's my code

Dim doc = XDocument.Load("Web.sitemap")

I'm trying to load the an XML file so that I can manipulate it. I'm getting an error saying that file cannot be found in the IIS Express directory. The file is actually located in the root directory of the project.

I've changed the Copy to Output Directory property to Copy always, but I'm still getting the same error. Is there any reason?

Thanks for helping

Jon Skeet
people
quotationmark

I'm getting an error saying that file cannot be found in the IIS Express directory.

Yes, because you're loading it with a relative path name, which means "relative to the current working directory"... which in this case is IIS.

You could either embed the data within the assembly, or use HttpServerUtility.MapPath to map your relative path to one within the directory containing your web site.

people

See more on this question at Stackoverflow