Application.VirtualDirectories Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the collection of virtual directories for the application.
public:
property Microsoft::Web::Administration::VirtualDirectoryCollection ^ VirtualDirectories { Microsoft::Web::Administration::VirtualDirectoryCollection ^ get(); };
public Microsoft.Web.Administration.VirtualDirectoryCollection VirtualDirectories { get; }
member this.VirtualDirectories : Microsoft.Web.Administration.VirtualDirectoryCollection
Public ReadOnly Property VirtualDirectories As VirtualDirectoryCollection
Property Value
A VirtualDirectoryCollection object that contains the virtual directories configured for the application.
Examples
The following example lists the Application objects found under the default Web site and then lists each VirtualDirectory object found in the VirtualDirectories property of each Application object.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;
using Microsoft.Web.Management;
namespace AdministrationSnippets
{
public class AdministrationApplicationVirtualDirectories
{
// Writes out the applications found under the default Web site
// and then writes out the virtual directories for each application.
public void GetVirtualDirectories()
{
ServerManager manager = new ServerManager();
Site defaultSite = manager.Sites["Default Web Site"];
foreach (Application app in defaultSite.Applications)
{
Console.WriteLine(
"Found application with the following path: {0}", app.Path);
Console.WriteLine("Virtual Directories:");
if ( app.VirtualDirectories.Count > 0 )
{
foreach ( VirtualDirectory vdir in app.VirtualDirectories )
{
Console.WriteLine(
" Virtual Directory: {0}", vdir.Path);
Console.WriteLine(
" |-PhysicalPath = {0}", vdir.PhysicalPath);
Console.WriteLine(
" |-LogonMethod = {0}", vdir.LogonMethod);
Console.WriteLine(
" +-UserName = {0}\r\n", vdir.UserName);
}
}
}
}
}
}
The following example creates an application under the default Web site and then creates a virtual directory for the application.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;
using Microsoft.Web.Management;
namespace AdministrationSnippets
{
public class AdministrationApplicationVirtualDirectories
{
// Creates an application under the default Web site and
// then creates a virtual directory for the application.
public void CreateVirtualDirectory()
{
ServerManager manager = new ServerManager();
Site defaultSite = manager.Sites["Default Web Site"];
Application photoApp = defaultSite.Applications.Add(
"/photos", @"C:\inetpub\wwwroot\photos\");
photoApp.VirtualDirectories.Add(
"/family", @"C:\inetpub\wwwroot\familyphotos\");
manager.CommitChanges();
}
}
}
Remarks
Each Application created has an implicit root virtual directory. Therefore, the VirtualDirectories property gets a collection that contains at least one object.