Tuesday, February 15, 2005

Diplay Virtual Direcotries in C#

the code i mentioned earlier fetches the website Names only..what if you want to show the virtual folders as well?well it`s not so difficult.If you run the code in my previous post,it will display a numeric number which is unique Identifer for each site hosted on IIS,this can be retrieved by calling Site.Name in for each loop
In order to retrieve the virtual folders under that specific Website simple do the following

//Save Website Unique Identified in a variable

String SiteId=Site.Name

DirectoryEntry W3SVC = new DirectoryEntry("IIS://" + ServerName + "/w3svc/"+SiteId+"/ROOT, "Domain/UserCode", "Password");


foreach (DirectoryEntry Site in W3SVC.Children)
{

//display Virtual Directories
Console.WriteLine(Site.Name.ToString());

}