Reputation: 469
How will I get the Mime Type or Content Type of a Specific file through its file extension? This program is developed in MVC3 Razor Syntax, the code looks like this:
if (System.IO.File.Exists(file))
return File(file, "application/pdf", id);
else
return RedirectToAction("Index");
I want to change the application/pdf to a dynamic value such that it would supply the MIME type through the id or the filename that is sent to the controller.
Upvotes: 0
Views: 1309
Reputation: 32596
You could look up the registry value at HKCR\<file extension>\Content Type
. This value doesn't exist for all file types, but probably does for all the file types you're interested in.
Upvotes: 1