views:

100

answers:

0

The following code create only virtual directory on local system , but i need to create on remote sytem ..help me.. Thanks, Sankar

DirectoryEntry iisServer; string VirDirSchemaName = "IIsWebVirtualDir"; public DirectoryEntry Connect() {
try { if (txtPath.Text.ToLower().Trim() == "localhost") iisServer = new DirectoryEntry("IIS://" + txtPath.Text.Trim() + "/W3SVC/1/Root"); else
iisServer = new DirectoryEntry("IIS://" + txtPath.Text + "/Schema/AppIsolated", "XYZ", "xyz");
iisServer.Dispose(); } catch (Exception e) { throw new Exception("Could not connect to: " + txtPath.Text.Trim(), e); }
return iisServer; }

public void CreateVirtualDirectory(DirectoryEntry iisServer)
{
    DirectoryEntry folderRoot = new DirectoryEntry("IIS://" + txtPath.Text + "/W3SVC/1/Root", "XYZ", "xyz");                
    folderRoot.RefreshCache();
    folderRoot.CommitChanges();
    try
    {
        DirectoryEntry newVirDir = folderRoot.Children.Add(txtName.Text, VirDirSchemaName);
        newVirDir.CommitChanges();                                                
        newVirDir.Properties["AccessRead"].Add(true);
        newVirDir.Properties["Path"].Add(@"\\abc\abc");           
        newVirDir.Invoke("AppCreate", true);            
        newVirDir.CommitChanges();
        folderRoot.CommitChanges();
        newVirDir.Close();
        folderRoot.CommitChanges();            
    }
    catch (Exception e)
    {
        throw new Exception("Error! Virtual Directory Not Created", e);
    }
}           

protected void btnCreate_Click(object sender, EventArgs e)    
{        
    try
    {
        CreateVirtualDirectory(Connect());
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }  
}
protected void Page_Load(object sender, EventArgs e)
{

}