A recent setup, one step, is to add a new MIME type to IIS. Log so that users can download IIS logs.
All of the operations of IIS can be done with the functionality in System.DirectoryServices. MIME types must also be. Sure enough, after a rummage search, found in MSDN. The original text is as follows: http://msdn2.microsoft.com/en-us/library/ms525901.aspx
The key step here is to refer to active DS IIS Namespace Provider So you can use the Iisole namespace, and IIsMimeType this class.
The actual code is not complex, all in the following, relatively simple, not much explanation.
Copy C # code save code
Using System;
Using System.IO;
Using System.DirectoryServices;
Using System.Reflection;
Using System.Runtime.InteropServices;
Using System.Collections; Namespace System_directoryservices_directoryentry_configiis {class Program {static void Main (string[] ar
GS) {setmimetypeproperty ("Iis://localhost/w3svc/1/root", ". Hlp", "Application/winhlp");
static void Setmimetypeproperty (String metabasepath, String newextension, String newmimetype) { MetabasePath is to the form "iis://<servername>/<path>"//For example "Iis://loca
Lhost/w3svc/1/root '//newextension is of the form ' .<extension> ' for example, '. HLP ' Newmimetype is of the form "<application>", for example, "Application/winhlp" Console.wri
Teline ("/nadding {1}->{2} to the" MimeMap property at {0}: ", MetabasePath, Newextension, Newmimetype);
try {DirectoryEntry path = new DirectoryEntry (MetabasePath); PropertyValueCollection propvalues = path.
properties["MimeMap"];
Console.WriteLine ("Old value of MimeMap has {0} elements", propvalues.count);
object exists = null; foreach (object value in Propvalues) {//Iisole requires a reference to the Active DS
IIS Namespace Provider in Visual Studio. NET iisole.iismimetype mimetypeobj = (iisole.iismimetype) value;
Console.WriteLine ("{0}->{1}", Mimetypeobj.extension, Mimetypeobj.mimetype);
if (newextension = = mimetypeobj.extension) exists = value;
} if (null!= exists) {propvalues.remove (exists); Console.WriteLine ("Found an entry for {0}; removing it before adding the new One. ", newextension);
} iisole.mimemapclass NEWOBJ = new Iisole.mimemapclass ();
Newobj.extension = newextension;
Newobj.mimetype = Newmimetype;
Propvalues.add (NEWOBJ);
Path.commitchanges ();
Console.WriteLine ("Done."); The catch (Exception ex) {if ("HRESULT 0x80005006" = ex.)
Message) Console.WriteLine ("Property MimeMap does not exist at {0}", MetabasePath);
else Console.WriteLine ("Failed in Setmimetypeproperty with the following exception:/n{0}", Ex.
message); }
}
}
}