public static void GetVirtualDirectoriesAssociatedWithApplication(Microsoft.Web.Administration.Application application) { VirtualDirectoryCollection directories = application.VirtualDirectories; foreach (VirtualDirectory directory in directories) { ConfigurationAttributeCollection attributes = directory.Attributes; foreach (ConfigurationAttribute attribute in attributes) { //put code here to work with each attribute } ConfigurationChildElementCollection childElements = directory.ChildElements; foreach (ConfigurationElement element in childElements) { //put code here to work with each ConfigurationElement } //get the directory.Path string path = directory.Path; //get the physical path string physicalPath = directory.PhysicalPath; } }
internal ConfigurationElement(ConfigurationElement element, string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity, FileContext core) { Methods = new ConfigurationMethodCollection(); this.FileContext = parent?.FileContext ?? element?.FileContext ?? core; Section = parent?.Section; this.InnerEntity = entity ?? element?.InnerEntity; if (element == null) { if (name == null) { throw new ArgumentException("empty name"); } ElementTagName = name; Attributes = new ConfigurationAttributeCollection(this); ChildElements = new ConfigurationChildElementCollection(this); Collections = new List<ConfigurationElementCollection>(); RawAttributes = new Dictionary<string, string>(); ParentElement = parent; if (parent == null) { if (schema == null) { throw new ArgumentException(); } Schema = schema; IsLocallyStored = true; } else { IsLocallyStored = !parent.Section.IsLocked; var collection = parent.Schema.CollectionSchema; if (collection == null) { Schema = parent.Schema.ChildElementSchemas[name]; } else { Schema = parent.Schema.CollectionSchema.GetElementSchema(name) ?? parent.Schema.ChildElementSchemas[name]; } if (Schema == null) { throw new ArgumentException("empty schema"); } } ParseAttributes(); } else { IsLocallyStored = element.IsLocallyStored; ElementTagName = element.ElementTagName; Attributes = element.Attributes; ChildElements = element.ChildElements; Collections = element.Collections; RawAttributes = element.RawAttributes; Schema = element.Schema; ParentElement = parent ?? element.ParentElement; if (schema != null) { // TODO: here we ignore second schema //throw new ArgumentException(); } } }