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.
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
. Both files physically exist. This is quite baffling, as it results in a FileNotFoundException
for non-PDFs.
/Documents//FID//TestDoc//27a835a5-bf70-4599-8606-6af64b33945d/FIDClasses.pdf
~/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文件和目录的权限,检查文件没有附加“区域”信息,因为您是从其他地方下载的。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.