joh*_*ohn 2 c# asp.net asp.net-mvc file-io
我使用MVC 2和C#创建了一个wedsite.其中一个页面是产品图像库.我已经存储了Db中图片的路径,例如../../Content/ProductImages/在控制器中我想要做一个foreach并获得显示的文件列表.我尝试了下面的代码:
List<string> files = new List<string>();
string path = Path.GetDirectoryName(typeModel.ArtUrl); // ../../Content/ProductImages/
foreach (string f in Directory.GetFiles(path))
{
files.Add(f);
}
Run Code Online (Sandbox Code Playgroud)
但是我收到错误,找不到路径"C:\ Program Files\Common Files\Microsoft Shared\Content\ProductImages \"的一部分.
为什么它走错路?这条路不存在
如果有人能告诉我如何获取../../Content/ProductImages/中包含的文件列表,将不胜感激.
谢谢约翰
尝试使用:
string path = Server.MapPath(typeModel.ArtUrl);
Run Code Online (Sandbox Code Playgroud)
MSDN 链接
| 归档时间: |
|
| 查看次数: |
1338 次 |
| 最近记录: |