Santry Technology Solutions, Content Management, DotNetNuke, SharePoint Consulting
Register | Login
Wednesday, January 07, 2009

Sections
  
About Us
  
Partners
Downloads
  
 WWWCoder.com Resource Directory

Using System.Directory Services for IIS Management
10/10/2005 9:59:23 AM

In this code snippet we will provide two methods for creating and removing virtual directories in IIS.

In this code block we're going to provide you with two methods for creating and removing IIS virtual directories using System.DirectoryServices dll. The DirectoryServices library provides you with a slew of network management features like user, group, domain management, and specifically for this article, IIS administration.

This code could be useful where you want to automate the creation of Websites.

Sub CreateVirtDir(ByVal DirName As String, ByVal PhysicalPath As String)
    ' reference the default server's root dir
    Dim rootDir As New System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root")
    ' create a child virtual directory
    Dim newDir As System.DirectoryServices.DirectoryEntry = rootDir.Children.Add(DirName, rootDir.SchemaClassName)
    ' set the physical path
    newDir.Properties("Path")(0) = PhysicalPath
    ' save the directory
    newDir.CommitChanges()
End Sub

This next methods deletes the newly created directory.

Sub RemoveVirtDir(ByVal DirName As String)
    Dim dir As New System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root")
    dir.Children.Remove(dir.Children.Find(DirName, dir.SchemaClassName))
    dir.CommitChanges()
End Sub

Remember in cases where the directory is not a physical directory off of the IIS root, you will need to write a routine to delete the folder.


Page Options:
format for printing  Format for Printer
email article  Email Page
add to your favorites   Add to Favorites
How would you rate the quality of this content?
Poor - - Excellent
Comments?
Overall Rating:
Comments Left:
Left on 1/12/2007 3:32:47 AM by Anonymous
Comments: if iam using this code it is giving error as "Access Denied"

No ratings available.
Left on 6/21/2006 8:27:23 AM by Anonymous
Comments: Avg Code. Need some more examples for creating and accessing web sites
  

 Latest Articles
  

 Latest News
  

 

Spotlight
Syndication

 


 


Digg This
 


DotNetNuke Platinum Benefactor

  
 

 Terms Of Use | Privacy Statement
 Copyright 2008 - Santry Technology Solutions, Box 172, Girard, PA 16417, (814) 774-0970