Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC 2网站-无法获取图像文件夹中的文件列表_C#_Asp.net_Asp.net Mvc_File Io - Fatal编程技术网

C# MVC 2网站-无法获取图像文件夹中的文件列表

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

我使用MVC2和C创建了一个wedsite。其中一个页面是产品图片库。我已将图片的路径存储在Db eg.././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);
}
但出现错误,无法找到路径“C:\Program Files\Common Files\Microsoft Shared\Content\ProductImages\”的一部分

为什么它走错了路??此路径不存在

如果有人能告诉我如何获取文件列表,我将不胜感激 ../../Content/ProductImages/

谢谢 John

尝试使用:

string path = Server.MapPath(typeModel.ArtUrl);
MSDN使用Server.MapPathtypeModel.ArtUrl;拥有真实的位置