views:

364

answers:

4

I have a whole bunch of string that are supposed to represent MIME types. However, some of these string have bad/invalid MIME types. Is there a way in the .NET framework to get a list of valid MIME types?

+1  A: 

while it's not canonical in the sense of being driven by a standard, the mime.types file delivered with any version of Apache will give you a good idea as to what it (and, therefore, a great deal of the web) thinks are valid MIME types.

DDaviesBrackett
+1  A: 

IANA have a list here. I would think that is more of an authority than most lists you can find.

adrianbanks
A: 

Following up from DDaviesBracket, you can find the latest mime.types here:

http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

and then consume the list (e.g. for C#):


string[] linesOfMimeTypes = File.ReadAllLines("mime.types");

List<string> mimeTypes = new List<string>();
foreach( string line in linesOfMimeTypes )
{
    if( line.length < 1 )
        continue;
    if( line[0] == '#' )
        continue;
    // else:
    mimeTypes.Add( line.Split( new char[] { ' ', '\t' } )[0] );
}

if( mimeTypes.Contains( oneToTest ) )
{
    // hooray!
}
maxwellb
+1  A: 

Check out this stack overflow post about adding custom mime types.

You should be able to do something like

using (DirectoryEntry mimeMap = new DirectoryEntry("IIS://Localhost/MimeMap"))
{
    PropertyValueCollection propValues = mimeMap.Properties["MimeMap"];
    foreach(IISOle.MimeMap mimeType in propValues) 
    //must cast to the interface and not the class
    {
      //access mimeType.MimeType to get the mime type string.
    }
}
Matthew Vines