2014-03-28 34 views
1

我正在從kendo上傳控件中移除圖像。system.io.file.exists無法在mvc4中工作

這是我的代碼

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(""); 
    } 

Physicalpath我已經是E:\ KARTHIK相關\ JPL \開發的\ src \ AssetTrackingSystem \ AssetTrackingSystem \ AssetAttachments \ Attach3.jpg

即使文件和可用目錄

if (System.IO.File.Exists(physicalPath)) 

正在返回錯誤並出現條件。

您的幫助將不勝感激。

+0

什麼是'physicalPath'的價值? –

回答

5

試試這個:

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

這種嘗試,

FileInfo fi = new FileInfo(Path.Combine(("~/AssetAttachments"),fileName)); 
if (fi.Exists) 
{ 
    fi.Delete(); 
} 
+0

即使f1.Exists返回False。 – Karthik

+0

這是不是來jaimin – Karthik

+0

@Karthik你有多個文件刪除? – Jaimin

相關問題