System.EnterpriseServices.Internal.IISVirtualRoot vr = new System.EnterpriseServices.Internal.IISVirtualRoot();
string sError;
vr.Create("IIS://localhost/W3SVC/" + GetSiteID(name of parent website) + "/Root", pathToFiles, nameofdirectory, out sError);
where GetSiteID is defined like
private static string GetSiteID(string strWebsiteName)
{
string strSiteID = string.Empty;
System.DirectoryServices.DirectoryEntry directoryEntry = new System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/");
foreach (System.DirectoryServices.DirectoryEntry tempDirectoryEntry in directoryEntry.Children)
{
if (Convert.ToString(tempDirectoryEntry.Properties["ServerComment"].Value).ToLower() == strDirectoryName.ToLower())
{
strSiteID = tempDirectoryEntry.Name;
break;
}
}
return strSiteID;
}