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 for that service in IIS. Usually what we do is after installing the service (by executing setup file) we go to the particular entry which is listed 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 (using C#) code sample would be of great help.

Thanks in advance.

I found this one but it is not working on Vista.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shreedhar EtteCommented:

Refer this article:

Hope this helps,
Shreedhar EtteCommented:
sachintha81Author Commented:
I actually need a C# code which does this process. As I've stated in the original question we already do this process manually and need to automate it.
sachintha81Author Commented:
By using the following code I managed to get the problem solved perfectly.

private static void SetMIMEType(DirectoryEntry directory, string extension, string type)
            bool MIMETypeExists = false;

            PropertyValueCollection propertyValues = directory.Properties["MimeMap"];
            if (propertyValues.Count > 0)
                //MIME¿¿¿¿JDF MIME¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿
                foreach (object obj in propertyValues)
                    if (((IISMimeType)obj).Extension == extension)
                        MIMETypeExists = true;

            //MIME¿¿¿¿JDF MIME¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿
            if (MIMETypeExists == false)
                MimeMapClass tempMIMEObj = new MimeMapClass();
                tempMIMEObj.Extension = extension;
                tempMIMEObj.MimeType = type;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.