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 ?
Asked
Active
Viewed 702 times
2 Answers
1
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);
}
}
0
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;
}
}
-
sorry - how does this help me find the already registered types? – Johnv2020 Nov 11 '11 at 15:01
-
Programmatically? From IIS Manager? From the registry? Please be more specific. – jrummell Nov 11 '11 at 15:04
-
apologies - not very clear. Need to find the registered types programatically as in the linked question. – Johnv2020 Nov 11 '11 at 15:08
-
What version of IIS? My updated answer has a sample that should work in IIS6. – jrummell Nov 11 '11 at 15:12
-
needs to be able to support iis6 & 7 - I've already tried this method and it doesn't work for iis 7. The registry method works for both, but not for any newly added types – Johnv2020 Nov 11 '11 at 15:20