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.

P.S.
I found this one but it is not working on Vista.
http://msdn.microsoft.com/en-us/library/ms525901.aspx
LVL 3
sachintha81Asked:
Who is Participating?
 
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;

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

            //MIME¿¿¿¿JDF MIME¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿
            if (MIMETypeExists == false)
            {
                MimeMapClass tempMIMEObj = new MimeMapClass();
                tempMIMEObj.Extension = extension;
                tempMIMEObj.MimeType = type;
                directory.Properties["MimeMap"].Add(tempMIMEObj);
            }
        }

Open in new window

0
 
Shreedhar EtteCommented:
Hi,

Refer this article:
http://www.hosting.com/support/dedicated/IIS/newmime/

Hope this helps,
Shree
0
 
Shreedhar EtteCommented:
0
 
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.