【发布时间】:2017-09-28 12:06:31
【问题描述】:
我想从文件夹内的文件夹/子文件夹中获取文件路径并将其填充到图像属性中。使用HttpContext.Current.Server.MapPath(@"~\StorageFolders");将返回完整路径并将返回
不允许加载本地资源
.
所以现在我正在使用循环和替换方法。我做得对吗? 或者我可以只获得不包括根文件夹的完整路径 例子 : 函数返回
C:\WebsiteRootFolder\Myfolder\SubFolderA\handsome.png
相对
我的文件夹\子文件夹A\handsome.png
总是回到网站的根目录
var fileList = Directory.GetFiles(path, "*", SearchOption.AllDirectories).ToList();
var rootpath= HttpContext.Current.Server.MapPath("~");
foreach (var item in fileList)
{
string s = item.Replace(rootpath, "");
Image image = new Image();
image.ImageUrl = ResolveUrl(@"~\"+ s);
//continue of codes
}
【问题讨论】: