How to register MIME types and file extensions to IIS?

We have a web service, for which to work a particular file extension (.jdf) needs to be registered under MIME types in IIS. Usually what we do is after installing the service (by executing setup file) we go to the particular entry under "Default Web Site" in IIS (We use Windows Vista + IIS 7) and under MIME settings manually add a MIME type. That is, we specify it as follows:

File Extension : .jdf
MIME type : text/xml

Now I'm assigned the task of automating this process. Which means this needs to be done automatically during the installation of the service. The installer is built using C# and Wix, so how can I register this using a C# code?

Please note that I'm just a beginner so any step-by-step instructions and code sample would be of great help. Thanks in advance.

Have a look at this thread.

Have a look at this thread.

adatapost, thanks a lot.
Yes I found that, but I have never used VB before so has some hard time understanding it. It'll be of great help if I can have some C# code.

I have tested that code included with MSDN link - It works fine. You need to add the .NET references of - System.DirectoryServices and a COM reference - Active DS IIS Namespace Provider.

I have tested that code included with MSDN link - It works fine. You need to add the .NET references of - System.DirectoryServices and a COM reference - Active DS IIS Namespace Provider.

I did add them.

Actually, when I execute the code the first time, it registers the extension. However from then on, the second or third time, it doesn't. The code is supposed to delete if it finds, but as I can understand it doesn't.

Btw, I'm not totally clear if the path Im giving is correct. In my IIS Manager, I have a site called "BSSTR" right under "Default Web Site". It is the one I want to set these MIME types. So, the metabase path I gave was :

"IIS://localhost/W3SVC/1/Root/BSSTR"

Is it correct?

How to register MIME types and file extensions to IIS?

we go to the particular entry under "Default Web Site" in IIS (We use Windows Vista + IIS 7) and under MIME settings manually add a MIME type. That is, we specify it as follows:

I missed "Vista + II7" and a note in the link you posted. Please read this blog/article - http://blogs.msdn.com/carlosag/archive/2006/04/17/MicrosoftWebAdministration.aspx and http://msdn.microsoft.com/en-us/magazine/cc163453.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.