This is My Action:
public FileResult ShowFile(long Id) {
DAL.Files.File file = new DAL.Files.FileAccess().GetById(Id);
return File(file.Content, file.FileType);
}
GetById
method return a file from SQL DB, when the file type is text or picture every thing is OK and correctly shown file, but when the file type is different like PDF that show some Unicode, so how can I shown PDF file correctly, or let the user download it?
The second argument to the
File()
method needs to be a mime type. So say your file is a PDF, it should work if you do this:To force a download instead, use the
File()
overload that takes a 3rd argument: