Reputation: 919
I want the user to be able to download .docx
documents from a website. The file exists and path is correct because file exists is returning true, but in the view, browser says FileNotFoundException
.
If I copy the error path and past into explorer address box, it opens the document.
public IActionResult DownloadDocument(int docID)
{
if (System.IO.File.Exists(@"C:\Users\Folder1\source\repos\Folder2\Folder3\Contents\Folder4\CustomerFeedback.docx"))
return File(@"C:\Users\Folder1\source\repos\Folder2\Folder3\Contents\Folder4\CustomerFeedback.docx", "application/docx", "CustomerFeedback.docx");
}
Upvotes: 1
Views: 105
Reputation: 31651
Try using the proper MIME type for DOCX - application/docx will not be served up by IIS as it's not a registered content type.
Content Type for DOCX: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Reference: https://stackoverflow.com/a/4212908/175679
Upvotes: 2