Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am able to create the virtual directory in loacal and remoting system with the below code

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);
            }
        }

but not able to invoke the virtual directory in remoting server with

deNewVDir.Invoke("AppCreate", 1) line, but in local its working fine.i am getting error like Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
Posted
Updated 3-Apr-10 6:42am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900