MVC 3 VirtualPathUtility 问题

发布于 2025-01-08 11:55:26 字数 377 浏览 0 评论 0原文

我有一个 MVC 3 应用程序,其中包含一个配置文件夹,其中包含特定于我的应用程序的 XML 文件。我试图在这样的视图中枚举文件:

string configPath = VirtualPathUtility.ToAbsolute("~/Configuration");
foreach (string path in Directory.EnumerateFiles(configPath, "*.xml"))
{
  // ...
}

但是,路径解析为 C:\Configuration,如错误消息所示:

找不到路径“C:\Configuration\”的一部分。

我缺少什么?

I have an MVC 3 app with a Configuration folder that holds XML files specific to my application. I'm trying to enumerate the files in a view like this:

string configPath = VirtualPathUtility.ToAbsolute("~/Configuration");
foreach (string path in Directory.EnumerateFiles(configPath, "*.xml"))
{
  // ...
}

However, the path resolves to C:\Configuration as evidenced by the error message:

Could not find a part of the path 'C:\Configuration\'.

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别念他 2025-01-15 11:55:26

我不知道但这应该在你的控制器中工作:

string configPath = Server.MapPath("~/Configuration");

I don't know but this should work in your controller:

string configPath = Server.MapPath("~/Configuration");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文