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
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)