The <directoryBrowse> element controls the information that is displayed in a directory listing when you enable directory browsing for your Web site or application.
The
<directoryBrowse> element can contain two attributes. The
enabled attribute determines whether directory browsing is enabled for the site, application, or directory. The
showFlags attribute defines the information about each file in the directory that Internet Information Services (IIS) will display. IIS can display the last modified date and time, the long date for the last modified date, the file size, and the file name extension. You can choose which of these, if any, IIS will display.
| |
IIS 7.0 |
IIS 6.0 |
| Notes |
The <directoryBrowse> element is new in IIS 7.0. |
The <directoryBrowse> element replaces the IIS 6.0 DirBrowseFlags metabase property. |
The <directoryBrowse> element is included in the default installation of IIS 7.0.
If directory browsing has been uninstalled, you can reinstall it using the following steps.
Windows Server 2008
- On the taskbar, click Start, point to Administrative Tools, and then click Server Manager.
- In the Server Manager hierarchy pane, expand Roles, and then click Web Server (IIS).
- In the Web Server (IIS) pane, scroll to the Role Services section, and then click Add Role Services.
- On the Select Role Services page of the Add Role Services Wizard, select Directory Browsing, and then click Next.
- On the Confirm Installation Selections page, click Install.
- On the Results page, click Close.
Windows Vista
- On the taskbar, click Start, and then click Control Panel.
- In Control Panel, click Programs and Features, and then click Turn Windows Features on or off.
- Expand Internet Information Services, expand World Wide Web Services, then expand Common Http Features.
- Select Directory Browsing, and then click OK.
How to enable directory browsing
- On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
- In the Connections pane, expand the server name, and then go to the site, application, or directory where you want to enable directory browsing.
- In the Home pane, double-click Directory Browsing.
- In the Actions pane, click Enable.
- In the Directory Browsing pane, select the options that correspond to the information you want to display for each item in the directory, and then click Apply.
The <directoryBrowse> element is configurable at the site level, application level, or directory level in the appropriate Web.config file.
Attributes
| Attribute |
Description |
enabled |
Optional Boolean attribute.
Specifies whether directory browsing is enabled (true) or disabled (false) on the Web server.
The default value is false. |
showFlags |
Optional flags attribute.
The showFlags attribute can have one or more of the following possible values. If you specify more than one value, separate the values with a comma (,). The default values are Date, Time, Size, Extension.
| Value |
Description |
Date |
Includes the last modified date for a file or directory in a directory listing. |
Extension |
Includes a file name extension for a file in a directory listing. |
LongDate |
Includes the last modified date in extended format for a file in a directory listing. |
None |
Specifies that only the file or directory names are returned in a directory listing. |
Size |
Includes the file size for a file in a directory listing. |
Time |
Includes the last modified time for a file or directory in a directory listing. |
|
Child Elements
None.
Configuration Sample
The following example enables directory browsing and uses the showFlags property to configure IIS to display the date and time modified for each item in the directory, along with each item's file size and file name extension.
<configuration>
<system.webServer>
<directoryBrowse enabled="true" showFlags="Date,Time,Extension,Size" />
</system.webServer>
</configuration>
The following examples enable directory browsing for a site named Contoso and use the showFlags property to configure IIS to display the date and time modified for each item in the directory, along with each item's file size and file name extension.
AppCmd.exe
appcmd.exe set config "Contoso" -section:system.webServer/directoryBrowse /enabled:"True" /showFlags:"Date, Time, Size, Extension"
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("Contoso");
ConfigurationSection directoryBrowseSection = config.GetSection("system.webServer/directoryBrowse");
directoryBrowseSection["enabled"] = true;
directoryBrowseSection["showFlags"] = @"Date, Time, Size, Extension";
serverManager.CommitChanges();
}
}
}
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("Contoso")
Dim directoryBrowseSection As ConfigurationSection = config.GetSection("system.webServer/directoryBrowse")
directoryBrowseSection("enabled") = True
directoryBrowseSection("showFlags") = "Date, Time, Size, Extension"
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso";
var directoryBrowseSection = adminManager.GetAdminSection("system.webServer/directoryBrowse",
"MACHINE/WEBROOT/APPHOST/Contoso");
directoryBrowseSection.Properties.Item("enabled").Value = true;
directoryBrowseSection.Properties.Item("showFlags").Value = "Date, Time, Size, Extension";
adminManager.CommitChanges();
VBScript
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso"
Set directoryBrowseSection = adminManager.GetAdminSection("system.webServer/directoryBrowse", "MACHINE/WEBROOT/APPHOST/Contoso")
directoryBrowseSection.Properties.Item("enabled").Value = True
directoryBrowseSection.Properties.Item("showFlags").Value = "Date, Time, Size, Extension"
adminManager.CommitChanges()