I'm trying to open a PDF file located inside the folder (Content/extras) in my app using the controller and is not working for me. The error I'm receiving is
"Could not find file 'C:/..../Content/extras/PDFName'" Exception details: System.IO.FileNotFoundException: Could not find file 'C:/..../Content/extras/PDFName'"
So basically it says that it can't find the file but the file is 100% in that location and the name is correct. I do notice though that is trying to find 'PDFName' instead of 'PDFName.pdf' so maybe that's what's wrong and is the 'MimeMapping' in the controller that is not coded correctly.
Here is my code:
Controller
public FileResult PDFFlyer()
{
string path = Server.MapPath(String.Format("~/Content/extras/PDFName"));
string mime = MimeMapping.GetMimeMapping(path);
return File(path, mime);
}
RouteConfig
routes.MapRoute(
name: "PDFFlyer",
url: "{filename}",
defaults: new { controller = "PDF", action = "PDFFlyer", filename =
UrlParameter.Optional }
);
The cshtml file
<a class="dropdown-item" href="@Url.Action("PDFFlyer", "PDF")" target="_blank">PDF Flyer</a>
What am I doing wrong? Again I'm guessing is the 'MimeMapping' Controller code that is incorrect because it doesn't seem to be looking for the '.pdf.' and is only looking for the PDFName, but not really sure what's wrong. Any suggestions? Thanks.