Reputation: 2146
as shown here its possible to get the "default" IIS mime types from HKEY_Classes_Root. However when I register a new type I cannot find the entry - does anyone know how I get read all IIS registered mime types progamatically ?
Upvotes: 0
Views: 712
Reputation: 2146
Sorry to answer my own question but the answer posted here (shown below) resolves this for both IIS 6 & 7
NameValueCollection map = new NameValueCollection();
using (DirectoryEntry entry = new DirectoryEntry("IIS://localhost/MimeMap"))
{
PropertyValueCollection properties = entry.Properties["MimeMap"];
Type t = properties[0].GetType();
foreach (object property in properties)
{
BindingFlags f = BindingFlags.GetProperty;
string ext = t.InvokeMember("Extension", f, null, property, null) as String;
string mime = t.InvokeMember("MimeType", f, null, property, null) as String;
map.Add(ext, mime);
}
}
Upvotes: 1
Reputation: 43077
You may have to add it in IIS.
http://technet.microsoft.com/en-us/library/cc725608(WS.10).aspx
Update
You could try the DirectoryServices API:
public static string GetMimeTypeFromExtension(string extension)
{
using (DirectoryEntry mimeMap =
new DirectoryEntry("IIS://Localhost/MimeMap"))
{
PropertyValueCollection propValues = mimeMap.Properties["MimeMap"];
foreach (object value in propValues)
{
IISOle.IISMimeType mimeType = (IISOle.IISMimeType)value;
if (extension == mimeType.Extension)
{
return mimeType.MimeType;
}
}
return null;
}
}
Can I setup an IIS MIME type in .NET?
Upvotes: 0