Click here to Skip to main content
13,344,016 members (98,886 online)
Click here to Skip to main content
Add your own
alternative version


25 bookmarked
Posted 18 Jan 2006

Editing virtual directories on multiple IIS sites and servers

, 18 Jan 2006
Rate this:
Please Sign up or sign in to vote.
A simple tool to view and edit virtual directories settings on multiple web sites and web servers.


This article is the Part II of a previous work of mine titled "Managing virtual directories on multiple IIS sites and servers". The Virtual Directory Viewer tool described there has been improved with some new features. This article focuses on those new features (and only on them - so, taking a look at the Part I is strongly recommended). The main new feature makes the Viewer capable of accessing virtual directory data hosted in the IIS metabase in a read/write fashion (no more in a limited, read-only way). So, the Viewer actually became an Editor, but we still simply call it Virtual Directory Viewer (v2).

New features in the Virtual Directory Viewer v2

The new features introduced in this version of the Virtual Directory Viewer (v2) are:

  • the ability to search a particular physical path (or path part) inside the set of data shown in the matrix, in order to find which virtual directory of which web site on which web server is currently pointing to it;
  • the ability to edit a cell in the matrix, actually inducing a modification to the virtual directory configuration on the correct web server and web site the cell itself refers;
  • the ability to inject (that is, simultaneously add) a new virtual directory definition to multiple web sites and web servers;
  • the ability to modify a virtual directory definition simultaneously on multiple web sites and web servers;
  • the ability to remove a virtual directory definition simultaneously from multiple web sites and web servers.

Buttons on the main form

The following table lists the buttons on the main form of the tool, and the corresponding features. For features already present in version 1, please refer to the Part I of this article.

ShapeFunctionDescriptionNew in v2
Load dataRetrieve data from specified web servers and web sitesNo
SaveSave current matrix on fileNo
LoadLoad matrix from fileNo
EditEdit selected virtual directory cellYes
InjectInject, modify, or remove a virtual directoryYes
FindFind a string and highlight all the cells containing itYes
Select AllSelect all cells in the current matrix (to prepare a copy & paste operation)No
TransposeTranspose the current matrix, by swapping row with columnsNo
Apply filterApply the filter conditionNo
Web sites...Open the "Web Site Chooser" dialog boxNo

How the editing feature has been implemented

As stated in the Introduction, the main difference between this version of the Virtual Directory Viewer tool and the previous one is the ability to edit the virtual directory configurations shown in the matrix. The editing feature is simply accomplished by code like this (see the btnOk_Click event handler in VDirEdit.vb), that makes use of the System.DirectoryServices.DirectoryEntry class:

Dim de As New DirectoryEntry(VDirMetabasePath)
Dim OldPhysPath As String = de.Properties("Path").Value()
Dim NewPhysPath As String = txtPhysPath.Text
de.Properties("Path")(0) = NewPhysPath

Of course, the need arises to store somewhere some information about the IIS metabase entry the user is going to edit. I decided to store these information as additional data directly related to each cell of the matrix. To achieve this goal, I created a simple class named VirtualDir, hosting all the info I needed about the virtual directory the user is going to edit (let me call them "metadata", needed for manipulating each single DirectoryEntry instance: the web server, the web site, the metabase path, the virtual directory logical name, and so on) and defined as follows:

Public Class VirtualDir

  Public VDName As String = ""
  Public VDPhysicalPath As String = ""
  Public VDWebSiteAndServer As String = ""
  Public VDMetabasePath As String = ""

  Public Overrides Function ToString() As String
    Return VDPhysicalPath
  End Function

End Class

This class is then directly instantiated when creating the DataSet and DataTable that support the matrix visualization: some columns of the DataTable are actually of type VirtualDir (see the btnLoadData_Click event handler in VDirViewer.vb):

VDirMatrix = New DataTable("VDirMatrix")
Dim col As New DataColumn("VDirName", Type.GetType("System.String"))
col = New DataColumn(dr("WebSiteName"), Type.GetType("VDirViewer.VirtualDir"))
col.DefaultValue = New VirtualDir

The ToString() method's override I did in the VirtualDir class guarantees some control about what the DataGrid will display in the corresponding cell, when the DataGrid itself is bound to the underlying DataTable.

The "metadata" I added behind each cell this way, need (of course!) to be persisted and retrieved when the user clicks on the Save and Load buttons. To accomplish this task, I created a class named VDirDataSet to be used instead of the standard DataSet class. VDirDataSet is a class derived from System.Data.DataSet to overload the WriteXml and ReadXml methods in order to achieve a sort of custom serialization/deserialization of customized DataSet columns (see the code in VDirDataSet.vb). The deserialization process (ReadXml methods) is obviously capable of recreating a DataTable containing some columns of type VirtualDir (compare the btnLoadData_Click procedure in VDirViewer.vb with the ReadXml procedure in VDirDataSet.vb).

How the search functionality has been implemented

The search functionality's goal is to provide a quick way to highlight those cells in the matrix that contain a virtual directory physical path matching with the given search string. To implement this kind of highlighting, I decided to create a specialized version of the DataGridTextBoxColumn class, capable of rendering itself using a different backcolor when the search string is found inside its content. So, the class I created contains the logic of searching and highlighting (see DataGridColoredTextBoxColumn.vb), and the execution of a Find operation actually becomes just a matter of creating a proper DataGridTableStyle and applying it to the shown DataGrid:

Private Sub cmdFind_Click(ByVal sender As System.Object, _
          ByVal e As System.EventArgs) Handles cmdFind.Click
    If dgMatrix.DataSource Is Nothing Then Exit Sub

    SearchString = InputBox("Enter the string you want to find:", _
                            "Find", SearchString)
    Catch ex As Exception
    End Try
    dgMatrix.TableStyles.Add(CreateGridStyle((SearchString <> "")))
End Sub

Private Function CreateGridStyle(Optional ByVal Search _
                 As Boolean = True) As DataGridTableStyle

    Dim ColWidth As New NameValueCollection
    ' Preserve column width from preceding TableStyle

    If Not CurrentTableStyle Is Nothing Then
      Dim gcs As DataGridColumnStyle
      For Each gcs In CurrentTableStyle.GridColumnStyles
        ColWidth(gcs.MappingName) = gcs.Width
    End If

    Dim dt As DataTable = CType(dgMatrix.DataSource, DataView).Table
    Dim GridStyle = New DataGridTableStyle
    GridStyle.MappingName = dt.TableName
    Dim nameColumnStyle As DataGridTextBoxColumn

    Dim dc As DataColumn
    For Each dc In dt.Columns
      If Search Then
        nameColumnStyle = New DataGridColoredTextBoxColumn
        nameColumnStyle = New DataGridTextBoxColumn
      End If
      nameColumnStyle.MappingName = dc.ColumnName
      nameColumnStyle.HeaderText = dc.ColumnName
      If Not ColWidth(dc.ColumnName) Is Nothing Then
        nameColumnStyle.Width = ColWidth(dc.ColumnName)
      End If
    CurrentTableStyle = GridStyle
    Return GridStyle
End Function

Points of interest

I think the major points of interest in this implementation are:

  • the use of DataTables with columns based on custom types;
  • modified serialization/deserialization of DataSets to support those custom types in columns;
  • the use of DataGridTableStyles and custom DataGridTextBoxColumns to provide a personalized rendering of data in the DataGrid.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Alberto Venditti
Technical Lead
Italy Italy
I was born in 1970.

My first computer experience dates back to early 80s, with a Sinclair ZX81.
From that time on, as many "friends" say, my IT-illness has increased year by year.

I graduated in Electronic Engineering and earned the following Microsoft certifications:
MCP, MCT, MCDBA, MCSD, MCAD, MCSD for .NET (early achiever).

I worked in IT as a developer, a teacher, a consultant, a technical writer, a technical leader.
IT knowledge applied to real life is my primary interest and focus.

You may also be interested in...


Comments and Discussions

GeneralLooks very cool Pin
BlueLoveCyn14-Mar-07 19:13
memberBlueLoveCyn14-Mar-07 19:13 
GeneralRe: Looks very cool Pin
Alberto Venditti14-Mar-07 23:32
memberAlberto Venditti14-Mar-07 23:32 
GeneralRe: Looks very cool Pin
BlueLoveCyn15-Mar-07 0:28
memberBlueLoveCyn15-Mar-07 0:28 
GeneralRe: Looks very cool Pin
BlueLoveCyn21-Mar-07 17:26
memberBlueLoveCyn21-Mar-07 17:26 
GeneralRe: Looks very cool Pin
Alberto Venditti22-Mar-07 1:03
memberAlberto Venditti22-Mar-07 1:03 
GeneralWill this work for shared website hosting Pin
chadbellan26-Jan-06 7:29
memberchadbellan26-Jan-06 7:29 
GeneralRe: Will this work for shared website hosting Pin
Alberto Venditti26-Jan-06 7:57
memberAlberto Venditti26-Jan-06 7:57 
GeneralRead/Write access Pin
chadbellan26-Jan-06 7:28
memberchadbellan26-Jan-06 7:28 
Can I use this to create a virtual directory and give it read/write access?
GeneralRe: Read/Write access Pin
Alberto Venditti26-Jan-06 7:52
memberAlberto Venditti26-Jan-06 7:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 19 Jan 2006
Article Copyright 2006 by Alberto Venditti
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid