C# MVC 2网站-无法获取图像文件夹中的文件列表
我使用MVC2和C创建了一个wedsite。其中一个页面是产品图片库。我已将图片的路径存储在Db eg.././Content/ProductImages中/ 在控制器中,我想做一个foreach并得到一个要显示的文件列表。我尝试了下面的代码:C# MVC 2网站-无法获取图像文件夹中的文件列表,c#,asp.net,asp.net-mvc,file-io,C#,Asp.net,Asp.net Mvc,File Io,我使用MVC2和C创建了一个wedsite。其中一个页面是产品图片库。我已将图片的路径存储在Db eg.././Content/ProductImages中/ 在控制器中,我想做一个foreach并得到一个要显示的文件列表。我尝试了下面的代码: List<string> files = new List<string>(); string path = Path.GetDirectoryName(typeModel.ArtUrl); // ../../Content/Pr
List<string> files = new List<string>();
string path = Path.GetDirectoryName(typeModel.ArtUrl); // ../../Content/ProductImages/
foreach (string f in Directory.GetFiles(path))
{
files.Add(f);
}
但出现错误,无法找到路径“C:\Program Files\Common Files\Microsoft Shared\Content\ProductImages\”的一部分
为什么它走错了路??此路径不存在
如果有人能告诉我如何获取文件列表,我将不胜感激
../../Content/ProductImages/
谢谢
John尝试使用:
string path = Server.MapPath(typeModel.ArtUrl);
MSDN使用Server.MapPathtypeModel.ArtUrl;拥有真实的位置