nI was searching for a way to get the MIME type of a file by file extension and .NET Framework 4.5 comes to the rescue.
n
nYou can make use of API GetMimeMapping which is found in the .NET Framework 4.5 System.Web.dll
n
nHere is the documentation of it – http://msdn.microsoft.com/en-us/library/system.web.mimemapping.getmimemapping.aspx
n
nExample on how you can use it
n
nstring mimeType = System.Web.MimeMapping.GetMimeMapping(fileName);
n
nIf you are running your ASP.NET web application in the integrated mode in IIS then this API actually uses the list of MIME types in the IIS and so seems to me that even if your IIS MIME types list gets upgraded, you dont need to update your code, huh..cool .. isn’t it?
n
nHope you find this useful.
n
nReference – http://blogs.msdn.com/b/webdev/archive/2013/02/14/getting-a-mime-type-from-a-file-extension-in-asp-net-4-5.aspx
n
nYou can make use of API GetMimeMapping which is found in the .NET Framework 4.5 System.Web.dll
n
nHere is the documentation of it – http://msdn.microsoft.com/en-us/library/system.web.mimemapping.getmimemapping.aspx
n
nExample on how you can use it
n
nstring mimeType = System.Web.MimeMapping.GetMimeMapping(fileName);
n
nIf you are running your ASP.NET web application in the integrated mode in IIS then this API actually uses the list of MIME types in the IIS and so seems to me that even if your IIS MIME types list gets upgraded, you dont need to update your code, huh..cool .. isn’t it?
n
nHope you find this useful.
n
nReference – http://blogs.msdn.com/b/webdev/archive/2013/02/14/getting-a-mime-type-from-a-file-extension-in-asp-net-4-5.aspx