Posted on Monday April 4, 2011

Listing all mime types without using OLE and IIS in .NET

If you’re offering uploading on a web application, or providing a file proxy of some sort, at some point the list of files you offer will exceed a simple switch statement.

In order for the file to be recognised correctly by the browser that’s downloading the file you need to pass the correct headers back. You can do this the long, more complete way by querying the IIS mimetype metabase (which requires COM interop with IIS6).

Or you can cheat and simply query an XML file list of mimetypes. The application below does this, based on a list from Update - that’s now a dead link. This link has a list (thanks Tim).

The full download includes the XML serialized file.


class Program
	static void Main(string[] args)
		var list = MimeType.Load();
		MimeType mimetype = list.FirstOrDefault(m => m.Extension == "jpg");

MimeType class