iis| site
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Windows.Forms.Design;
Using System.DirectoryServices;
Using System.Reflection;
Using System.Text.RegularExpressions;
int totalservercount=0;
DirectoryEntry RootFolder = new DirectoryEntry ("Iis://localhost/w3svc");
Totalservercount=rootfolder. Children.SchemaFilter.Count;
foreach (DirectoryEntry Child in RootFolder.) Children)
{
if (child. schemaClassName = = "IIsWebServer")
{
Totalservercount+=1;
}
}
Loop to get all site detail properties to write to the array
string [] Arrayserverid = new string[totalservercount];//site identifier
string [] Arrayserverip = new string[totalservercount];//Site Host Header
string [] Arrayserverport = new string[totalservercount];//Site Host Header
string [] Arrayserverheader = new string[totalservercount];//Site Host Header
string [] Arrayserverpath = new string[totalservercount];//Site Host Header
string [] arrayservercomment = new string[totalservercount];//Site Host Header
string [] arrayserverbinds = new string[totalservercount];//Site Host Header
String currentserverbindings;//binding Host header IP Port string
Char[] a= ":". ToCharArray ();
string [] currentbingdings =new string[2];
int i=0;
foreach (DirectoryEntry Child in RootFolder.) Children)
{
if (child. schemaClassName = = "IIsWebServer")
{
Arrayserverid.setvalue (child. Name.tostring (), i);
Arrayservercomment.setvalue (child. properties["ServerComment"]. Value.tostring (), i);
Currentserverbindings=child. properties["ServerBindings"]. Value.tostring ();
Currentbingdings=currentserverbindings.split (a);
Arrayserverip.setvalue (Currentbingdings[0],i);
Arrayserverport.setvalue (Currentbingdings[1],i);
Arrayserverheader.setvalue (Currentbingdings[2],i);
foreach (DirectoryEntry rootchild in child. Children)
{
if ((Rootchild.schemaclassname = = "IIsWebVirtualDir") && (rootChild.Name.ToString () = = "Root")
{
if (rootchild.properties["Path"). Value==null)
{
Arrayserverpath.setvalue ("", I);
}
Else
{
Arrayserverpath.setvalue (rootchild.properties["Path"). Value.tostring (), i);
}
}
}
I+=1;
}
}
Write to the DataGrid.
Loop reads data from an array
for (i=0;i<totalservercount;i++)
{
LISTVIEW1.ITEMS.ADD ((i+1). ToString ());
Listview1.items[i]. SubItems.Add (Arrayserverid.getvalue (i). ToString ());
Listview1.items[i]. SubItems.Add (Arrayservercomment.getvalue (i). ToString ());
Listview1.items[i]. SubItems.Add (Arrayserverip.getvalue (i). ToString ());
Listview1.items[i]. SubItems.Add (Arrayserverport.getvalue (i). ToString ());
Listview1.items[i]. SubItems.Add (Arrayserverheader.getvalue (i). ToString ());
Listview1.items[i]. SubItems.Add (Arrayserverpath.getvalue (i). ToString ());
}