Burak SARICA said:
Thanx andrew.
let's say there is a directory under default web site. (not an application)
can we handle this directory? And if we can, how can we make it an
application? (Or will i only execute your code? (I couldn't try your
code))
Burak,
Sure you can do it. To get my code to work you have to add a reference to
the System.DirectoryServices assembly, and then add a using statement to the
top of your class file:
using System.DirectoryServices;
The path variable in the method i posted points to an adsi path, not a file
system path. Note to create an iis application you must first ensure that
the IIS metabase contains an IIsWebDirectory entry for your phsyical
directory.
Try the following code:
{
CreateWebDirectory(RootAdsiPath, "YourFolderName");
CreateApplication(RootAdsiPath + "/YourFolderName", "Your friendly
application name", IIsInProcessFlags.Pooled);
}
public static string RootAdsiPath {
get { return "IIS://" + Environment.MachineName + "/W3SVC/1/Root"; }
}
public void CreateApplication(string path, string name, IIsInProcessFlags
flag) {
using (DirectoryEntry entry = new DirectoryEntry(path)) {
entry.Invoke("AppCreate2", new object[1] { (int)flag });
entry.Properties["AppFriendlyName"].Value = name;
entry.CommitChanges();
}
}
public void CreateWebDirectory(string parentPath, string name) {
if (EntryExists(parentPath + "/" + name))
return;
using (DirectoryEntry entry = new DirectoryEntry(parentPath)) {
DirectoryEntry newEntry = (DirectoryEntry)entry.Invoke("Create", new
object[2] { "IIsWebDirectory", name });
newEntry.CommitChanges();
}
}
public bool EntryExists(string path) {
try {
using (DirectoryEntry entry = new DirectoryEntry(path)) {
return entry.Guid != Guid.Empty;
}
} catch {
return false;
}
}
hth
andrew