获取IIS虚拟目录内容的路径

我试图获取IIS虚拟目录的路径,但我的解决方案返回给我

文件:/// E:!/ Programy%20C#Katalog2 \ Katalog2 \ MvcApplication1 \查看\首页\ JPG \ 1001 \ 1 \ 0

我的代码:

public ActionResult Searcher(string symbol, string dekoracja) { if (symbol != "" && dekoracja != "") { MyModel.Symbol = symbol; MyModel.Dekorajca = dekoracja; string path = Server.MapPath(Url.Content(@"~/Images/jpg/" + PathBuilder.Instance.pathBuilder(symbol, dekoracja))); DirectoryInfo Dir = new DirectoryInfo(path); try { FileInfo[] FileList = Dir.GetFiles("*jpg"); foreach (FileInfo fileInfo in FileList) { //tylko jpg ma wyswietlac do refaktoryzacji MyModel.ImageList.Add(fileInfo.FullName); } }... 

我是asp.net的新手,我不知道如何采取正确的路径(〜/ Vievs / Home / Jpg / …),我需要它放入图像src。 Symbol和Dekoracja是ActionResult参数中给出的文件夹名称。

 public class PathBuilder { public static readonly PathBuilder Instance = new PathBuilder(); public string pathBuilder(string Symbol, string Dekoracja) { return Symbol + @"\" + Dekoracja + @"\"; } } 

您的图片不应位于/Views文件夹中。 在您的应用程序中创建一个新文件夹(比如Images ),然后生成标签的src属性中使用的路径的代码应该是

 string folder = String.Format("Images/{0}/{1}", symbol, dekoracja); // or whatever you call your folder var path = Server.MapPath(folder); FileInfo[] files = new DirectoryInfo(path).GetFiles(); // or GetFiles("*jpg") if it contains other image types List imageList = files.Select(x => String.Format("/{0}/{1}", folder, x.Name)).ToList();