我遇到了一个与之前的帖子有关的奇怪错误。我在下载前检查文件是否存在。这适用于 PDF,但不适用于任何其他类型的文档。
这是我的控制器操作以及 PDF 和 PowerPoint 文件的典型路径,PowerPoint 不起作用,File.Exists
总是返回false
. 这两个文件都实际存在。这非常令人费解,因为它会导致FileNotFoundException
非 PDF 文件。
/Documents//FID//TestDoc//27a835a5-bf70-4599-8606-6af64b33945d/FIDClasses.pdf
~/Documents//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");
}