11 March, 2009
0 Comments
0 categories
/// <summary> /// Does the given IIS website contain virtualdirectories. /// </summary> /// <returns></returns> public bool DoesWebsiteContainVirtualDirectories(string website) { if (string.IsNullOrEmpty(website)) { throw new Exception("Parameter [website] can't be null or empty"); } bool result = false; DirectoryEntry w3svc = new DirectoryEntry("IIS://localhost/w3svc"); foreach (DirectoryEntry site in w3svc.Children) { if (site.Properties["ServerComment"] != null) { if (site.Properties["ServerComment"].Value != null) { if (site.SchemaClassName.Equals("IIsWebServer") && site.Properties["ServerComment"].Value.ToString().Equals(website)) { foreach (DirectoryEntry child in site.Children) { if (!result) { foreach (PropertyValueCollection property in child.Properties) { if (property.Value != null) { if (property.PropertyName.Equals("KeyType") && property.Value.ToString().Equals("IIsWebVirtualDir")) { return true; } } } } } } } } } return result; }