I'm trying to create a virtual directory using the code:
using System;
using System.Collections.Generic
;
using System.Text;
using System.DirectoryServices;
namespace VirtualDirectoryCreator
{
class Program
{
static void Main(string[] args)
{
string name = "mytestdir";
//welcome of sorts
DirectoryEntry rootDir = new DirectoryEntry("IIS://Loca
lhost/W3SV
C/1/Root")
;
DirectoryEntry vDir = rootDir.Children.Add(name,
"IIsWebVirtualDir");
rootDir.RefreshCache();
vDir.Properties["AccessRea
d"].Insert
(0, true);
vDir.Properties["Path"].In
sert(0, "c:\temp");
vDir.CommitChanges();
rootDir.CommitChanges();
// Create a Application
vDir.Invoke("AppCreate", true);
vDir.CommitChanges();
}
}
}
however, evertime i try to run the program an exception gets thrown at the line
DirectoryEntry vDir = rootDir.Children.Add(name,
"IIsWebVirtualDir");
Any idea on what could be causing this exception?
Start Free Trial