Using the System.Director yServices namespace classes.
Herewith something (not tested) to get you started...
Willy.
using System;
using System.Director yServices;
using System.IO;
class IISVdir {
// Authorization flags
const int MD_AUTH_ANONYMO US = 0x00000001; //Anonymous authentication
available.
const int MD_AUTH_BASIC = 0x00000002; //Basic authentication available.
const int MD_AUTH_NT = 0x00000004; //Windows authentication schemes
available.
// Browse flags
const int MD_DIRBROW_SHOW _DATE = 0x00000002; //Show date.
const int MD_DIRBROW_SHOW _TIME = 0x00000004; // Show time.
const int MD_DIRBROW_SHOW _SIZE = 0x00000008; //Show file size.
const int MD_DIRBROW_SHOW _EXTENSION = 0x00000010; //Show file name
extension.
const int MD_DIRBROW_LONG _DATE = 0x00000020; //Show full date.
const int MD_DIRBROW_LOAD DEFAULT = 0x40000000; // Load default page, if it
exists.
const uint MD_DIRBROW_ENAB LED = 0x80000000;
// Access Flags
const int MD_ACCESS_READ = 0x00000001; //Allow read access.
const int MD_ACCESS_WRITE = 0x00000002; //Allow write access.
const int MD_ACCESS_EXECU TE = 0x00000004; //Allow file execution
(includes script permission).
const int MD_ACCESS_SOURC E = 0x00000010; //Allow source access.
const int MD_ACCESS_SCRIP T = 0x00000200; // Allow script execution.
const int MD_ACCESS_NO_RE MOTE_WRITE = 0x00000400; // Local write access
only.
const int MD_ACCESS_NO_RE MOTE_READ = 0x00001000; // Local read access
only.
const int MD_ACCESS_NO_RE MOTE_EXECUTE = 0x00002000; // Local execution
only.
const int MD_ACCESS_NO_RE MOTE_SCRIPT = 0x00004000; // Local host access
only.
public static void Main() {
// Create a virtual directory and application in the IIS Root
CreateVirtualDi rectory("IIS://localhost/W3SVC/1/Root", "someWeb",
"c:\\somefolder ");
}
public static void CreateVirtualDi rectory(string parent, string
virtDirectory, string physicalDir)
{
// Delete VDir if already exists
if(CheckIfExist s(parent, virtDirectory))
{
Delete(parent, virtDirectory, physicalDir);
}
// Create physical directory if non existent
if (!Directory.Exi sts(physicalDir ))
{
Directory.Creat eDirectory(phys icalDir);
}
// remove / or \\ at end of path if any
string str = physicalDir;
if (physicalDir.En dsWith("/") || physicalDir.End sWith("\\"))
{
str = physicalDir.Rem ove(physicalDir .Length - 1, 1);
}
DirectoryEntry folderRoot = new DirectoryEntry( parent);
folderRoot.Refr eshCache();
DirectoryEntry vDir =
folderRoot.Chil dren.Add(virtDi rectory,"IIsWeb VirtualDir");
vDir.CommitChan ges();
// Set Properties
vDir.Properties["Path"].Value =str;
vDir.Properties["AuthFlags"].Value = MD_AUTH_ANONYMO US | MD_AUTH_NT;
vDir.Properties["DefaultDoc "].Value = "default.as px";
vDir.Properties["DirBrowseFlags "].Value = MD_DIRBROW_SHOW _DATE |
MD_DIRBROW_ENAB LED |
MD_DIRBROW_SHOW _SIZE | MD_DIRBROW_SHOW _EXTENSION |
MD_DIRBROW_LONG _DATE | MD_DIRBROW_LOAD DEFAULT;
vDir.Properties["AccessFlag s"].Value = MD_ACCESS_READ |
MD_ACCESS_SCRIP T;
// add a custom header, format is (key: value)
object[] headers = {"TestValue: 1", "AnotherOne : 1234"};
vDir.Properties["HttpCustomHead ers"].AddRange(heade rs);
// Call AppCreat2 to create a Web application (0 =In-proc, 1 =
Out-proc, 2 = Pooled) , required by IIS, not used by ASP.NET
object[] applicationType = new object[]{0};
vDir.Invoke("Ap pCreate2", applicationType );
// Save Changes
vDir.CommitChan ges();
folderRoot.Comm itChanges();
vDir.Close();
folderRoot.Clos e();
}
internal static bool CheckIfExists(s tring RootWeb, string VirtualDirector y)
{
DirectoryEntry directoryEntry = new DirectoryEntry( String.Concat(R ootWeb,
"/", VirtualDirector y));
try
{
string name = directoryEntry. Name;
return true;
}
catch
{
bool flag = false;
return flag;
}
}
internal static void Delete(string RootWeb, string VirtualDirector y, string
PhysicalDirecto ry)
{
try
{
DirectoryEntry root = new DirectoryEntry( RootWeb);
DirectoryEntry vdir = root.Children.F ind(VirtualDire ctory,
root.SchemaClas sName);
// Remove Entry from container.
string strName = vdir.Name;
root.Children.R emove(vdir);
Console.WriteLi ne(strName+ " entry is removed from container.");
root.CommitChan ges();
root.Close();
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
}
// delete physical dir
Directory.Delet e(PhysicalDirec tory, true);
}
}
"Jacky Luk" <no****@nospam. com> wrote in message
news:uY******** ******@TK2MSFTN GP11.phx.gbl...
Hi all,
If I need to make a C# application, do I need to set up a virtual dir such
as inetroot on the Harddisks. How do I set up such thingy?
Thanks
Jack