XDocument: 找不到文件 'C:\Program Files (x86)\IIS Express\myfile

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

这是我的代码

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

我正在尝试加载 XML 文件以便我可以对其进行操作。我收到一条错误消息,指出无法在 IIS Express 目录中找到该文件。该文件实际上位于项目的根目录中。

我已将 复制到输出目录 属性 更改为 Copy always,但我仍然遇到相同的错误。有什么原因吗?

感谢您的帮助

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

是的,因为您使用相对路径名加载它,这意味着 "relative to the current working directory"...在本例中是 IIS。

您可以将数据嵌入到程序集中,或者使用 HttpServerUtility.MapPath 将您的相对路径映射到包含您网站的目录中的路径。