Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

DirectoryServices.DirectoryEntry - Creating virtual directories in

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
paul - 08 Aug 2005 14:26 GMT
I'm using the DirectoryServices class to try and create new virtual
directories in IIS.
Here's the code I'm using:

System.DirectoryServices.DirectoryEntry oDE;
System.DirectoryServices.DirectoryEntries oDC;
System.DirectoryServices.DirectoryEntry oVirDir;
string sIISPath = @"IIS:\\localhost\W3SVC\1\Root";
//Assuming it exists, we bind our DirectoryEntry object, oDE, to this root
using:
if  (VirDirExists(sIISPath))
{
oDE = new System.DirectoryServices.DirectoryEntry(sIISPath);
//We obtain a collection of all of the children virtual directories under
this root object using:
oDC = oDE.Children;
//Add a new member to this collection and bind it to a new DirectoryEntry
object, oVirDir, thus creating a new
//virtual directory with:
oVirDir = oDC.Add(virDirName, oDE.SchemaClassName.ToString());
//Commit the changes to the IIS Metabase.
oVirDir.CommitChanges();
//Setting and Updating Any of the Properties on IIS
//We additionally need to assign a physical path to this new virtual
directory, using a straightforward
//property-setting approach:
oVirDir.Properties["Path"][0]= physicalPath;
oVirDir.Properties["DefaultDoc"][0] = "home_here.aspx";
oVirDir.Properties["AppFriendlyName"][0] = textBox1.Text.Trim();
oVirDir.Properties["CreateProcessAsUser"][0] = true;
oVirDir.CommitChanges();

This works fine in that it adds the entry to the default web site and set's
the appropriate properties.  However, it does not 'create' the application.  
You need to physically go into the virtual directory properties(in the IIS
snapin), go to the Virtual Directory tab, and click the <CREATE> button next
to the Application Name textbox in order to get the virtual directory to work
in IIS.

I can't seem to find an method that does this programatically in the
DirectoryServices class.  Does any one knows what this would be or if there
is another way to create virtual directories programatically in IIS?

Thanks for your help

Paul
Jakob Christensen - 08 Aug 2005 16:38 GMT
Hey Paul,

You need to set the AppRoot property as well.  This will cause the
application to be created.  E.g.:

vdir.Properties["AppRoot"].Value = "/LM/W3SVC/1/Root/TESTSITE";

HTH, Jakob.
Signature

http://www.dotninjas.dk
http://www.powerbytes.dk

> I'm using the DirectoryServices class to try and create new virtual
> directories in IIS.
[quoted text clipped - 42 lines]
>
> Paul
paul - 08 Aug 2005 16:51 GMT
That was it.
Thanks!

> Hey Paul,
>
[quoted text clipped - 51 lines]
> >
> > Paul
bk - 09 Aug 2005 00:51 GMT
> I can't seem to find an method that does this programatically in the
> DirectoryServices class.  Does any one knows what this would be or if
> there
> is another way to create virtual directories programatically in IIS?

Paul,

You should invoke the method AppCreate, AppCreate2 or AppCreate3 on the
IIsWebDirectory directory entry object, eg:

public void CreateApplication(string path, string name, string
applicationPool, IIsInProcessFlags flag)
{
   if (path == null)
       throw new ArgumentNullExpcetion("path");

   if (name == null)
       throw new ArgumentNullException("name");

   using (DirectoryEntry entry = new DirectoryEntry(path))
   {
       entry.Invoke("AppCreate2", new object[1] { (int)flag });
       entry.Properties["AppFriendlyName"].Value = name;
       if (applicationPool != null)
           entry.Properties["AppPoolId"].Value = applicationPool;
       entry.CommitChanges();
   }
}

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.