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
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