简体   繁体   English

ASP.NET MVC FileNotFoundException错误

[英]ASP.NET MVC FileNotFoundException error

I'm having a weird error which is related to an earlier post. 我有一个与之前的帖子有关的奇怪错误。 I am checking if a file exists before downloading. 下载前我正在检查文件是否存在。 This works for PDFs, but not for any other type of document. 这适用于PDF,但不适用于任何其他类型的文档。

Here is my controller action and the typical path for a PDF and a PowerPoint file, the PowerPoint does not work, the File.Exists always returns false . 这是我的控制器操作,以及PDF和PowerPoint文件的典型路径,PowerPoint不起作用, File.Exists始终返回false Both files physically exist. 这两个文件实际上都存在。 This is quite baffling, as it results in a FileNotFoundException for non-PDFs. 这非常令人困惑,因为它会导致非PDF的FileNotFoundException

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

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

The joke is that copying and pasting the file path into explorer leads to the file, so what could be the problem? 开玩笑的是,将文件路径复制并粘贴到资源管理器中会导致文件,那么可能是什么问题呢?

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

检查PPT文件和目录的权限,检查文件没有附加“区域”信息,因为您是从其他地方下载的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM