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?
Asked
Active
Viewed 2,997 times
2
-
Are you looking for a list for reference or are you looking for some method for validating MIME types within your application? – James Conigliaro Jun 10 '09 at 18:20
-
@James: I'm looking for a way to validate. – Esteban Araya Jun 10 '09 at 20:06
4 Answers
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