C# IIS MimeType Compiler Problem

  • Thread starter Thread starter Alex Duggleby
  • Start date Start date
A

Alex Duggleby

Hi everybody,

I'm trying to add some mime types to the local IIS server using some c#
code.

The code I'm using is:

---snip---

DirectoryEntry _mimeMap =
new DirectoryEntry("IIS://localhost/MimeMap");

System.DirectoryServices.PropertyValueCollection _pcv =
_mimeMap.Properties["MimeMap"];

IISOle.MimeMapClass _mc =
new IISOle.MimeMapClass();

_mc.Extension = ".test";
_mc.MimeType = "application/octet-stream";

---/snip---

My Visual Studio Project has references to IISOle and ActiveDs. When
using Intellisense the object is there, I can browse the object browser,
everything shows up. I can see the MimeMap and MimeMapClass.

When I compile I keep getting:

[...]\IISController.cs(34,4): error CS0246: The type or namespace name
'IISOle' could not be found (are you missing a using directive or an
assembly reference?)

I really have no idea how IntelliSense can find the IISOle Namespace and
the Classes, but the compiler can't. Am I doing something obviously wrong?

I've seen the article:

http://msdn.microsoft.com/library/d...p_security_using_system_directoryservices.asp

but I figured that if IntelliSense can find it, then it should be alright.

Is there any other way to add Mime Types to the IIS Metabase?

Thanks in advance,
Alex Duggleby
 
Alex,

I have successfully used the following code to retrieve the Mime
Types:



using System;
using System.DirectoryServices;

using ActiveDs;

namespace MimeTypes
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{

// Look up the IIS Meta base for the mime mapping
DirectoryEntry mimeMap = new
DirectoryEntry("IIS://LocalHost/MimeMap");
System.DirectoryServices.PropertyValueCollection mimeMaps =
mimeMap.Properties["MimeMap"];
foreach (object map in mimeMaps)
{
IISOle.IISMimeType oleMap = map as IISOle.IISMimeType;
if (oleMap != null)
{
Console.WriteLine("{0} -> {1}", oleMap.Extension,
oleMap.MimeType);
}
}

mimeMap.Dispose();

}
}
}



I added the two references:

Active DS Type Library
Active DS IIS Namespace Provider

from the COM tab.
 
Back
Top