我正在从kendo上传控件中删除图片。
这是我的代码
public ActionResult Remove(string[] fileNames)
{
if (fileNames != null)
{
foreach (var fullName in fileNames)
{
var fileName = Path.GetFileName(fullName);
var physicalPath = Server.MapPath(Path.Combine(("~/AssetAttachments"),fileName));
if (System.IO.File.Exists(physicalPath))
{
System.IO.File.Delete(physicalPath);
}
}
}
return Content("");
}
物理路径是E:\ karthik相关\ JPL \ Dev \ Src \ AssetTrackingSystem \ AssetTrackingSystem \ AssetAttachments \ Attach3.jpg
即使文件和目录可用
if (System.IO.File.Exists(physicalPath))
正在返回false并且已经过时了。
我们将不胜感激。
答案 0 :(得分:6)
试试这个:
foreach (var fullName in fileNames)
{
var physicalPath = System.IO.Path.Combine(HttpContext.Current.Server.MapPath("~/AssetAttachments"), fullName);
if (System.IO.File.Exists(physicalPath))
{
System.IO.File.Delete(physicalPath);
}
}
答案 1 :(得分:1)
试试这个,
FileInfo fi = new FileInfo(Path.Combine(("~/AssetAttachments"),fileName));
if (fi.Exists)
{
fi.Delete();
}