public void createvirtualdir() { string strSchema = "IIsWebVirtualDir"; string strRootSubPath = "IIS://" + strdest + "/W3SVC/1/Root"; string strphysicalpath=@"c:\\inetpub\wwwroot\"; DirectoryEntry deRoot = new DirectoryEntry(strRootSubPath); try { if(CheckIfExists(strRootSubPath,"TestVirDir1")) { strphysicalpath=strphysicalpath + "\\" +"TestVirDir1"; Delete(strRootSubPath, "TestVirDir1", strphysicalpath); } deRoot.Username = some username deRoot.Password = some password DirectoryEntry deNewVDir = deRoot.Children.Add("TestVirDir1", strSchema); deNewVDir.Properties["Path"].Insert(0, "C:\\TestWebApp\\TestWebApp"); // Just for example. //deNewVDir.Properties["physicalPath"].Insert(0, strphysicalpath); // deNewVDir.Properties["AppFriendlyName"].Value = "TestWebApp"; //deNewVDir.InvokeSet("AppFriendlyName","TestWebApp"); //deNewVDir.Properties["DefaultDoc"].Value = "Default.aspx"; // Create a Application if (strSchema == "IIsWebVirtualDir") deNewVDir.Invoke("AppCreate", 1); deNewVDir.CommitChanges(); deRoot.CommitChanges(); PropertyValueCollection scriptMapVals = deNewVDir.Properties["ScriptMaps"]; ArrayList objScriptMaps = new ArrayList(); string frameworkVersion = "4.0.30128"; //ConfigurationManager.AppSettings["frameworkVersion"]; Regex versionRegex = new Regex(@"(?<=\\v)\d{1}\.\d{1}\.\d{1,5}(?=\\)"); //Assuming the version will always be something like n.n.nnnnn foreach (string scriptMapVal in scriptMapVals) { if (scriptMapVal.Contains("Framework")) { objScriptMaps.Add(versionRegex.Replace(scriptMapVal, frameworkVersion)); } else { objScriptMaps.Add(scriptMapVal); } } deNewVDir.Properties["ScriptMaps"].Value = objScriptMaps.ToArray(); // Save Changes deNewVDir.CommitChanges(); deRoot.CommitChanges(); deNewVDir.Close(); deRoot.Close(); //Console.WriteLine("Virtual Directory TestVirDir has been created"); MessageBox.Show("Virtual Directory TestVirDir has been created"); } catch (Exception ex) { //Console.WriteLine("Error: " + ex.Message); MessageBox.Show("Error: " + ex.Message); } }
(Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)