2010-05-20 60 views
1

我在這是關係到一個較早的帖子一個奇怪的錯誤。我正在下載之前檢查文件是否存在。這適用於PDF,但不適用於任何其他類型的文檔。ASP.NET MVC FileNotFoundException異常錯誤

這是我的控制器操作和PDF和PowerPoint文件的典型路徑,PowerPoint不起作用,File.Exists總是返回false。兩個文件都物理存在。這是很令人費解,因爲它導致FileNotFoundException非PDF文件。

/Documents//FID//TestDoc//27a835a5-bf70-4599-8606-6af64b33945d/FIDClasses.pdf

〜/文檔// // FID // pptest ce36e7a0-14de-41f3- 8eb7-0d543c7146fe/PPttest.ppt

這個笑話是複製和粘貼文件路徑到資源管理器導致文件,所以可能是什麼問題?

[UnitOfWork] 
public ActionResult Download(int id) 
{ 
    Document doc = _documentRepository.GetById(id); 

    if (doc != null) 
    { 
     if (System.IO.File.Exists(Server.MapPath(doc.filepath))) 
     { 
      _downloadService.AddDownloadsForDocument(doc.document_id, _UserService.CurrentUser().user_id); 
      return File(doc.filepath, doc.mimetype, doc.title); 
     } 
    } 
    return RedirectToAction("Index"); 
} 
+0

我假設你已經breakpointed了「如果System.IO ......」行,以檢查它不是文檔是空時,它不應該是... – NibblyPig 2010-05-20 17:05:01

+0

感謝,對您的答覆,是因爲我說的,文件路徑錯誤返回,我已經複製並粘貼該路徑到Windows資源管理器和文件是存在的。文件路徑是文檔的屬性,所以DOC不能爲空。 – bongoo 2010-05-20 17:08:08

回答

0

檢查的PPT文件和目錄的權限,檢查該文件沒有附帶一定的「區域」信息,因爲你從別的地方下載它。

+0

謝謝,我已經看了看權限,似乎罰款,奇怪的是,它發生在所有的文件除了PDF文件。 – bongoo 2010-05-20 17:14:57

相關問題