简体   繁体   中英

How to remove IIS 6 web directory property using directoryentry in C#

I want to delete a particular property of IIS when directory from Metabase. Can anyone please help me? How can we do that with DirectoryEntry class in C#?

Use following code sample from MSDN

using System;
using System.DirectoryServices; 

class MyClass1
{
   static void Main()
   {
      try
      {
         String strPath = "IIS://localhost/W3SVC/1/Root";
         String strName = "";

         // Create a new 'DirectoryEntry' with the given path.
         DirectoryEntry myDE = new DirectoryEntry(strPath);
         DirectoryEntries myEntries = myDE.Children;

         // Create a new entry 'Sample' in the container.
         DirectoryEntry myDirectoryEntry = 
            myEntries.Add("Sample", myDE.SchemaClassName);
         // Save changes of entry in the 'Active Directory'.
         myDirectoryEntry.CommitChanges();
         Console.WriteLine (myDirectoryEntry.Name + 
            " entry is created in container.");

         // Find 'Sample' entry in container.
         myDirectoryEntry = myEntries.Find("Sample", myDE.SchemaClassName);
         Console.WriteLine(myDirectoryEntry.Name + " found in container.");
         // Remove 'Sample' entry from container.
         strName = myDirectoryEntry.Name;
         myEntries.Remove(myDirectoryEntry);
         Console.WriteLine(strName+ " entry is removed from container.");

      }
      catch(Exception e)
      {
         Console.WriteLine("The following exception was raised : {0}",
            e.Message);
      }
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM