Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi All,

I'm trying to install a web setup in that i'm using custom actions for deleting the default virtual directories which is created by the MSI and creating custom virtual directories.
The directories are creating fine, but the when I reset the IIS the custom virtual directories are gone and the deleted default virtual directories are came.

Resources used : Windows server 2003, IIS 6

Here the code used for deleting virtual directory and creatign virtual directory

VB
Create Virtual Directory:
<pre lang="vb">Private Sub CreateVDir(ByVal strMetabasePath As String, ByVal strVdirName As String, ByVal strPhysicalPath As String, ByVal AppName As String)
        Try
            Dim objSite As New DirectoryEntry(strMetabasePath)

            If (CheckIfVDirExists(objSite, strVdirName)) Then
                DeleteVirtualDirectory(strVdirName)
            End If

            Dim strClassName As String = objSite.SchemaClassName.ToString()
            If strClassName.EndsWith("Server") OrElse strClassName.EndsWith("VirtualDir") Then
                Dim objVdirs As DirectoryEntries = objSite.Children
                Dim objNewVdir As DirectoryEntry = objVdirs.Add(strVdirName, strClassName.Replace("Service", "VirtualDir"))
                objNewVdir.Properties("Path")(0) = strPhysicalPath
                objNewVdir.Properties("AccessScript")(0) = True
                objNewVdir.Properties("AppFriendlyName")(0) = strVdirName
                objNewVdir.Properties("AppIsolated")(0) = "1"
                objNewVdir.Properties("AppPoolId").Value = AppName
                objNewVdir.Properties("AppRoot")(0) = "/LM" + strMetabasePath.Substring(strMetabasePath.IndexOf("/", "IIS://".Length))
                objNewVdir.CommitChanges()
                objNewVdir.Properties("AppFriendlyName")(0) = strVdirName
                objNewVdir.Invoke("AppCreate", True)
                objSite.CommitChanges()
            Else
                Throw New InstallException("Failed. A virtual directory can only be created in a site or virtual directory node.")
            End If
        Catch exError As Exception
            Throw exError
        End Try
    End Sub

Delete Virtual Directory:
Private Sub DeleteVirtualDirectory(ByVal VirtualDirName As String)
        Try
            Dim Parent As New DirectoryEntry(StrMetabasePath)
            Dim Parameters As [Object]() = {"IIsWebVirtualDir", VirtualDirName}
            Parent.Invoke("Delete", Parameters)
            Parent.CommitChanges()
        Catch ex As Exception
           Throw New InstallException("Error While deleting the virtual directories." & ex.Message)
        End Try
    End Sub



Thanks,
Dhilip
Posted
Updated 25-Mar-13 5:09am
v2
Comments
iismoove 2-Apr-13 15:10pm    
Have you tried stopping IIS before you delete the VDir? I noticed with our IIS, we need to stop it, create/delete the VDir, and then restart IIS.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900