MVC 3 VirtualPathUtility 问题
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道但这应该在你的控制器中工作:
I don't know but this should work in your controller: