system.io.file.exists不在mvc4中工作

Kar*_*hik 2 asp.net-mvc-4 kendo-upload

我从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("");
    }
Run Code Online (Sandbox Code Playgroud)

物理路径是E:\ karthik相关\ JPL\Dev\Src\AssetTrackingSystem\AssetTrackingSystem\AssetAttachments\Attach3.jpg

即使文件和目录可用

  if (System.IO.File.Exists(physicalPath))
Run Code Online (Sandbox Code Playgroud)

正在返回虚假并且出现状况.

我们将不胜感激.

Jey*_*mov 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);
     }
}
Run Code Online (Sandbox Code Playgroud)