Click here to Skip to main content
6,631,404 members and growing! (16,685 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » .NET Framework » Utilities     Advanced License: The Code Project Open License (CPOL)

IIS Utility to Create Virtual Directory - Advanced

By eOrdinary

This tool is useful to create new virtual directories with extra settings in One Click !
VB.NET 1.1, .NET 2.0, Win2K, WinXP, Win2003IIS 5.1, IIS 6, VS.NET2003, VS2005, Architect, Dev
Posted:11 Sep 2007
Updated:23 Oct 2007
Views:21,071
Bookmarked:27 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
5 votes for this article.
Popularity: 2.14 Rating: 3.07 out of 5
1 vote, 20.0%
1
1 vote, 20.0%
2

3
1 vote, 20.0%
4
2 votes, 40.0%
5
Screenshot - IISUtility.jpg

Introduction

This is a simple IIS utility to create a new virtual directory with predefined settings. I found a sample code to create a virtual directory on the Internet (Original article here). I just added some features into that.....
So the credit for this goes to original author.

Background

In big projects, it is often required to create and configure new virtual dirs. I tried to create the utility which will ease the work of the configuration management team.

Using the Code

The code is attached. Now it's your job to enhance the utility by adding some more features!

Dim IISSchema As New System.DirectoryServices.DirectoryEntry_
    ("IIS://localhost/Schema/AppIsolated")
            Dim CanCreate As Boolean = _
                Not IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN"
            IISSchema.Dispose()
            Dim AppName As String = txtVirtDirName.Text, path As String = txtPath.Text
            If CanCreate Then
                Dim PathCreated As Boolean

                Dim IISAdmin As New System.DirectoryServices.DirectoryEntry_
                        ("IIS://localhost/W3SVC/1/Root")
                'make sure folder exists
                If Not System.IO.Directory.Exists(path) Then
                    System.IO.Directory.CreateDirectory(path)
                    PathCreated = True
                End If

                Dim VDir As System.DirectoryServices.DirectoryEntry = Nothing
                Dim bAlreadyThere As Boolean = False
                'If the virtual directory already exists then delete it
                For Each VD As System.DirectoryServices.DirectoryEntry In _
                        IISAdmin.Children()
                    If VD.Name = AppName Then
                        IISAdmin.Invoke("Delete", New String() _
                        {VD.SchemaClassName, AppName})
                        IISAdmin.CommitChanges()
                        'MsgBox("Virtual directory already exists..!.", _
                            MsgBoxStyle.Information, "Create Virtual Directory")
                        'Exit Sub
                        VDir = VD
                        bAlreadyThere = False
                        Exit For
                    End If
                Next VD

                'Create and setup new virtual directory
                If (Not bAlreadyThere) Then
                    VDir = IISAdmin.Children.Add(AppName, "IIsWebVirtualDir")
                End If
                VDir.Properties("Path").Item(0) = path
                VDir.Properties("AppFriendlyName")(0) = AppName
                VDir.Properties("EnableDirBrowsing").Item(0) = True
                VDir.Properties("AccessRead").Item(0) = True
                VDir.Properties("AccessExecute").Item(0) = True
                VDir.Properties("AccessWrite").Item(0) = False
                VDir.Properties("AccessScript").Item(0) = True
                VDir.Properties("AuthNTLM").Item(0) = chkWinAuthenticate.Checked _
                    'True 'Integreted Windows(Authontocation)
                VDir.Properties("AuthAnonymous").Item(0) = chkAnonymous.Checked
                If (chkAnonymous.Checked) Then
                    VDir.Properties("AnonymousUserName").Item(0) = txtUser.Text
                    VDir.Properties("AnonymousUserPass").Item(0) = txtPassword.Text
                    VDir.Properties("AnonymousPasswordSync").Item(0) = False
                End If
                VDir.Properties("EnableDefaultDoc").Item(0) = chkDefaultDocs.Checked
                VDir.Properties("DefaultDoc").Item(0) = txtDefaultDocuments.Text
                VDir.Properties("AspEnableParentPaths").Item(0) = True

                VDir.CommitChanges()

                If Not bAlreadyThere Then VDir.Invoke("AppCreate2", 2)
                If (chkASPNET2.Checked) Then
                    Dim prcProcess As System.Diagnostics.Process
                    prcProcess = System.Diagnostics.Process.Start_
                    (System.Environment.GetEnvironmentVariable("windir") + _
                        "\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis", _
                        " -s /W3SVC/1/Root/" + txtVirtDirName.Text)
                    prcProcess.WaitForExit()
                End If
                MessageBox.Show("Done", "Hurray...", MessageBoxButtons.OK, _
                    MessageBoxIcon.Information)

            End If

Features

  1. Create new virtual directories overwriting existing ones
  2. Configure ASP.NET 2.0 or 1.1 Framework
  3. Configure your own user under anonymous access
  4. Configure default pages
  5. Test immediately

Enhancements -- Your Job!

  1. I don't have IIS 7. Test it on IIS 7 and let me know
  2. Configure the appropriate application pool in IIS 6

NOTE : This is raw code just to get an idea of how to manage virtual directories. You need to modify the code according to your need.

License

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

About the Author

eOrdinary


Member

Occupation: Other
Location: United States United States

Other popular .NET Framework articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 16 of 16 (Total in Forum: 16) (Refresh)FirstPrevNext
GeneralCode fails for IIS7 PinmemberNanaAM3:03 11 Oct '07  
GeneralRe: Code fails for IIS7 PinmemberHemantPune3:34 11 Oct '07  
Generalbug PinmemberFredrik B23:48 12 Sep '07  
GeneralRe: bug PinmemberHemantPune23:56 12 Sep '07  
GeneralExcellent Article Pinmemberrajantawate1(http//www.jhatak.com)7:23 12 Sep '07  
General[Message Deleted] PinmemberHemantPune3:40 12 Sep '07  
GeneralRe: Remote Server PinmemberSteve Hansen4:51 12 Sep '07  
GeneralRe: Remote Server PinmemberHemantPune19:10 12 Sep '07  
GeneralRe: Remote Server PinmemberSteve Hansen21:24 12 Sep '07  
GeneralRe: Remote Server PinmemberAndrew Harrs20:13 12 Sep '07  
GeneralRe: Remote Server PinmemberHemantPune20:19 12 Sep '07  
GeneralRe: Remote Server PinmemberAndrew Harrs20:32 12 Sep '07  
GeneralRe: Remote Server PinmemberHemantPune20:35 12 Sep '07  
GeneralRe: Remote Server PinmemberAndrew Harrs21:07 12 Sep '07  
AnswerRe: Remote Server PinmemberHemantPune21:11 12 Sep '07  
GeneralRe: Remote Server PinmemberAndrew Harrs21:44 12 Sep '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 23 Oct 2007
Editor: Deeksha Shenoy
Copyright 2007 by eOrdinary
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project