Delete an object from the IIS metabase

Simple enough to do, as long as you remember you have to remove it from the parent item’s children list.

public static void DeleteMetabaseObject(string metabasePath) { try { string deleteParent = metabasePath.Substring(0,metabasePath.LastIndexOf("/")); string deleteName = metabasePath.Substring(metabasePath.LastIndexOf("/") + 1); DirectoryEntry parent = new DirectoryEntry(deleteParent); DirectoryEntry childToDelete = new DirectoryEntry(metabasePath); parent.Children.Remove(childToDelete); parent.CommitChanges(); } catch(System.Runtime.InteropServices.COMException e1) { throw e1; } }