Cannot create Virtual Directory in IIS from asp.net

G

Guest

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
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top