2

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?

Esteban Araya
  • 29,284
  • 24
  • 107
  • 141

4 Answers4

2

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

adrianbanks
  • 81,306
  • 22
  • 176
  • 206
1

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.

Dan Davies Brackett
  • 9,811
  • 2
  • 32
  • 54
1

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.
    }
}
Community
  • 1
  • 1
Matthew Vines
  • 27,253
  • 7
  • 76
  • 97
0

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
  • 13,366
  • 2
  • 25
  • 35