C#操作IIS添加MIME类型(win2003)

public static void AddMIMEType()
{
    DirectoryEntry rootEntry = GetDirectoryEntry("IIS://localhost/w3svc/1/root");
    foreach(PropertyValueCollection pc in rootEntry.Properties)
    {
        Console.WriteLine(pc.PropertyName+":"+pc.Value);
    }
    //rootEntry.Properties["MimeMap"].Add(
    IISOle.MimeMapClass _NewMime = new IISOle.MimeMapClass();          //新建MIME类型
    _NewMime.Extension = ".xap";
    _NewMime.MimeType = ".xap";
    rootEntry.Properties["MimeMap"].Add(_NewMime);  //添加MIME类型

    rootEntry.CommitChanges();//更改目录

}

 

这里面关键一步是引用Active DS IIS Namespace Provider,这样你就能使用IISOle这个命名空间,和IISMimeType 这个类

引用COM组件“Active DS Namespace provider”,嵌入式互操作性=false

posted @ 2012-10-18 15:40  踏浪帅  阅读(1050)  评论(0编辑  收藏  举报