本文介绍了获取IIS虚拟目录内容的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图获取IIS虚拟目录的路径,但我的解决方案返回给我
Im trying to take path to IIS virtual catalog but my solution returns me
我的代码:
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参数中给出的文件夹名称。
Im new in asp.net and I dont know how to take correct path (~/Vievs/Home/Jpg/...),i need it to put into image src. Symbol and Dekoracja are folder names given in parameter of ActionResult.
public class PathBuilder
{
public static readonly PathBuilder Instance = new PathBuilder();
public string pathBuilder(string Symbol, string Dekoracja)
{
return Symbol + @"\" + Dekoracja + @"\";
}
}
推荐答案
您的图片不应位于 / Views
文件夹中。在您的应用中创建一个新文件夹(比如 Images
),然后生成在 src
< img>
标记的属性应为
Your images should not be inside your
/Views
folder. Create a new folder in your app (say Images
), then the code to generate the paths to be used in the src
attribute of an <img>
tag should be
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<string> imageList = files.Select(x => String.Format("/{0}/{1}", folder, x.Name)).ToList();
这篇关于获取IIS虚拟目录内容的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!