Retrieval Of Virtual Directories In IIS

Retrieving all virtual directories present in IIS using ASP.NET 2.0

This is a bit different from the above coding style. First of all, let us look at the program.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As DataTable = getVirtualRootStruct()
Dim dr As DataRow
Dim searcher As New ManagementObjectSearcher("root\MicrosoftIISv2", "SELECT * FROM IIsWebVirtualDir")
For Each queryObj As ManagementObject In searcher.Get()
dr = dt.NewRow
dr("AppRoot") = queryObj("AppRoot")
dr("Caption") = queryObj("Caption")
dr("Description") = queryObj("Description")
dr("Name") = queryObj("Name")
dr("Status") = queryObj("Status")
Me.GridView1.DataSource = dt
Catch err As ManagementException
End Try
End Sub
To get the virtual directory information, we need to work with the class “IIsWebVirtualDir”. It has got a lot of properties. I just selected only the most important ones. I am using another routine to form a structure, to store that property information. The routine is as follows.

Private Function getVirtualRootStruct() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("AppRoot"))
dt.Columns.Add(New DataColumn("Caption"))
dt.Columns.Add(New DataColumn("Description"))
dt.Columns.Add(New DataColumn("Name"))
dt.Columns.Add(New DataColumn("Status"))
Return dt
End Function


Post a Comment

Note: Only a member of this blog may post a comment.