Configuration Paths <configPaths>

Overview

The <configPaths> element lists the locations where a configuration setting is set across the Internet Information Services (IIS) 7 distributed configuration file system. The contents of the <configPaths> element are generated dynamically, and can be accessed programmatically to list configuration settings starting from a user-specified path through each descendant path. You can also list the settings in the ApplicationHost.config and Web.config files by using the <configPaths> element.

The <configPaths> element contains a collection of <searchResult> elements that specify the following information:

  • The path attribute of each <searchResult> element specifies the absolute virtual path of the configuration file for the search result.
  • The locationPath attribute of each <searchResult> element specifies the relative path for the <location> tag inside the configuration file that is specified by the path attribute.

    Note: If the <searchResult> element points to a .config file, the locationPath attribute for the <searchResult> element will contain an empty string.
  • The status attribute of each <searchResult> element contains an HRESULT code for the search result.
  • Each <searchResult> element contains a collection of <section> elements that contain the name of each element in the search results.

Note: The <configPaths> element and its child elements are read-only and cannot be configured by an end user.

Compatibility

Version Notes
IIS 7.5 The <configPaths> element was not modified in IIS 7.5.
IIS 7.0 The <configPaths> element was introduced in IIS 7.0.
IIS 6.0 N/A

Setup

The <configPaths> element is included in the default installation of IIS 7.

How To

There is no user interface for configuring the <configPaths> element for IIS 7. For examples of how to configure the <configPaths> element programmatically, see the Code Samples section of this document.

Configuration

Attributes

None.

Child Elements

Element Description
searchResult Contains a collection of configuration search results.

Configuration Sample

Note: The <configPaths> element is generated dynamically. Because of this, you cannot add a <configPaths> element to your configuration files. For examples of how to access the <configPaths> element programmatically, see the Code Samples section of this document.

Sample Code

The following code examples use the <configPaths> element to search the Default Web Site configuration namespace for every <system.webServer/defaultDocument> element, and then output the path and location for each element to the console.

AppCmd.exe

Note: You cannot query <configPaths> settings using AppCmd.exe.

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetWebConfiguration("Default Web Site");
         ConfigurationSection configPathsSection = config.GetSection("configPaths");
         ConfigurationElementCollection searchResultCollection = configPathsSection.GetCollection();

         foreach (ConfigurationElement searchResultElement in searchResultCollection)
         {
            string path = (string)searchResultElement["path"];
            string locationPath = (string)searchResultElement["locationPath"];

            foreach (ConfigurationElement sectionElement in searchResultElement.GetCollection())
            {
               if (string.Compare("system.webServer/defaultDocument",
                  (string)sectionElement["name"], false) == 0)
               {
                  Console.WriteLine("Path: " + path);
                  if (!String.IsNullOrEmpty(locationPath))
                  {
                     Console.WriteLine("\tLocation: " + locationPath);
                     Console.WriteLine("\t\tName: " + sectionElement["name"]);
                  }
                  else Console.WriteLine("\tName: " + sectionElement["name"]);
               }
            }
         } 
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetWebConfiguration("Default Web Site")
      Dim configPathsSection As ConfigurationSection = config.GetSection("configPaths")
      Dim searchResultCollection As ConfigurationElementCollection = configPathsSection.GetCollection
      For Each searchResultElement As ConfigurationElement In searchResultCollection
         Dim path As String = CType(searchResultElement("path"), String)
         Dim locationPath As String = CType(searchResultElement("locationPath"), String)
         For Each sectionElement As ConfigurationElement In searchResultElement.GetCollection
            If (String.Compare("system.webServer/defaultDocument", _
                  CType(sectionElement("name"), String), False) = 0) Then
               Console.WriteLine(("Path: " + path))
               If Not String.IsNullOrEmpty(locationPath) Then
                  Console.WriteLine((vbTab & "Location: " + locationPath))
                  Console.WriteLine((vbTab & vbTab & "Name: " + sectionElement("name")))
               Else
                  Console.WriteLine((vbTab & "Name: " + sectionElement("name")))
               End If
            End If
         Next
      Next
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject("Microsoft.ApplicationHost.WritableAdminManager");
var configPathsSection = adminManager.GetAdminSection("configPaths", "MACHINE/WEBROOT/APPHOST/Default Web Site");
var searchResultCollection = configPathsSection.Collection;

for (var i = 0; i < searchResultCollection.Count; i++)
{
   var searchResultElement = searchResultCollection.Item(i);
   var path = searchResultElement.GetPropertyByName("path").Value;
   var locationPath = searchResultElement.GetPropertyByName("locationPath").Value;

   sectionElementCollection = searchResultElement.Collection;
   for (var j = 0; j < sectionElementCollection.Count; j++)
   {
      var sectionElement = sectionElementCollection.Item(j);
      var name = sectionElement.GetPropertyByName("name").Value;
      if (name == "system.webServer/defaultDocument")
      {
         WScript.Echo("Path: " + path);
         if (locationPath!="")
         {
            WScript.Echo("\tLocation: " + locationPath);
            WScript.Echo("\t\tName: " + name);
         }
         else WScript.Echo("\tName: " + name);
      }
   }
}

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
Set configPathsSection = adminManager.GetAdminSection("configPaths", "MACHINE/WEBROOT/APPHOST/Default Web Site")
Set searchResultCollection = configPathsSection.Collection

For i = 0 To CInt(searchResultCollection.Count) - 1
   Set searchResultElement = searchResultCollection.Item(i)
   path = searchResultElement.GetPropertyByName("path").Value
   locationPath = searchResultElement.GetPropertyByName("locationPath").Value
   Set sectionElementCollection = searchResultElement.Collection
   For j = 0 To CInt(sectionElementCollection.Count) - 1
      Set sectionElement = sectionElementCollection.Item(j)
      name = sectionElement.GetPropertyByName("name").Value
      If name = "system.webServer/defaultDocument" Then
         WScript.Echo "Path: " + path
         If locationPath<>"" Then
            WScript.Echo(vbTab & "Location: " + locationPath)
            WScript.Echo(vbTab & vbTab & "Name: " + name)
         Else
            WScript.Echo(vbTab & "Name: " + name)
         End if
      End If
   Next
Next
Deprecated Elements