Cannot create Virtual Directory in IIS from asp.net

Discussion in 'ASP .Net' started by =?Utf-8?B?U3RlcGhhbmU=?=, Dec 8, 2004.

  1. Hi,

    I'm trying to create a virtual directory dynamically in my web site using
    ASP.NET. I received this error:

    System.Runtime.InteropServices.COMException (0x800700B7): Cannot create a
    file when that file already exists.
    at System.DirectoryServices.Interop.IAdsContainer.Create(String
    className, String relativeName)
    at System.DirectoryServices.DirectoryEntries.Add(String name, String
    schemaClassName)
    at LsAdmin.Test.createVirtualDirectory(String username)

    The thing is that this virtual directory does not exist.

    Here's my code:

    // Gets the root of the web server
    DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");
    int siteId = 1;
    IEnumerator list = root.Children.GetEnumerator();
    // Find my web site which is named LiveSnap
    while (list.MoveNext() && !isFound)
    {
    DirectoryEntry e = (DirectoryEntry)list.Current;
    if(e.SchemaClassName == "IIsWebServer")
    {
    string desc = (string)e.Invoke("Get","ServerComment");
    if(desc == LIVESNAP_NAME)
    {
    siteId = Convert.ToInt32(e.Name);
    liveSnap = e;
    isFound = true;
    }
    }
    }
    if (isFound && liveSnap != null)
    {
    // Creates the virtual directory
    DirectoryEntry liveSnapVDir = liveSnap.Children.Add(username,
    "IISWebVirtualDir");
    liveSnapVDir.Properties["AppIsolated"][0] = 2;
    liveSnapVDir.Properties["Path"][0] = userPath;
    liveSnapVDir.Properties["AccessFlags"][0] = 513;
    liveSnapVDir.Properties["FrontPageWeb"][0] = 1;
    liveSnapVDir.Properties["AppRoot"][0] = "LM/W3SVC/"+siteId+"/"+username;
    liveSnapVDir.Properties["AppFriendlyName"][0] = username;
    liveSnapVDir.CommitChanges();
    liveSnap.CommitChanges();
    }

    The error comes from the line liveSnap.Children.Add(username,
    "IISWebVirtualDir");

    Any idea why?

    Thanks,

    Stephane
    =?Utf-8?B?U3RlcGhhbmU=?=, Dec 8, 2004
    #1
    1. Advertising

  2. Hi,

    I solve my problem. I delete the line livesnap = e to add a new one after
    the while block like this:

    liveSnap = new DirectoryEntry("IIS://localhost/W3SVC/"+siteId+"/ROOT");

    Stephane
    =?Utf-8?B?U3RlcGhhbmU=?=, Dec 9, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Conorozzo

    Create IIS Virtual Directory from ASP.NET page...

    David Conorozzo, Nov 2, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    3,030
    David Conorozzo
    Nov 10, 2003
  2. Matt
    Replies:
    1
    Views:
    755
    Sherif ElMetainy
    Nov 10, 2003
  3. Eskimo
    Replies:
    5
    Views:
    134
    Joe Kaplan \(MVP - ADSI\)
    Nov 8, 2004
  4. Eskimo

    IIS Virtual Directory Create Failure :(

    Eskimo, Nov 4, 2004, in forum: ASP .Net Web Services
    Replies:
    4
    Views:
    176
    Eskimo
    Nov 22, 2004
  5. Matt
    Replies:
    2
    Views:
    138
    dlbjr
    Nov 9, 2003
Loading...

Share This Page