The following code works only for local system but i need to be work in remote/another system also.. While execute with remote system error come like this: Access is Denied. And also Give solution to acces privileges of access another system.
Thanks,
Sankar.
public DirectoryEntry Connect()
{
DirectoryEntry iisServer = null;
try
{
if (txtDirPath.Text.ToLower().Trim() == "localhost")
iisServer = new DirectoryEntry("IIS://" + txtDirPath.Text.Trim() + "/W3SVC/1/Root");
else
{
//Server name:-- txtDirPath.Text="servername/another systemname"
iisServer = new DirectoryEntry("IIS://" + txtDirPath.Text.Trim() + "/W3SVC/1/Root", "abc", "xyz");
}
}
catch (Exception e)
{
throw new Exception("Could not connect to: " + txtDirPath.Text.Trim(), e);
}
return iisServer;
}
public static string VirDirSchemaName = "IIsWebVirtualDir";
private void button1_Click(object sender, RoutedEventArgs e)
{
try
{
CreateVirtualDirectory(Connect());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void CreateVirtualDirectory(DirectoryEntry iisServer)
{
try
{
DirectoryEntry newVirDir = iisServer.Children.Add(txtName.Text.Trim(), VirDirSchemaName);
newVirDir.CommitChanges();
newVirDir.Properties["AccessRead"].Add(true);
newVirDir.Properties["Path"].Add(txtDirPath.Text);
//newVirDir.Properties["Path"].Add(@"\\servername(OR) anothersystemname");
newVirDir.Invoke("AppCreate", true);
newVirDir.CommitChanges();
iisServer.CommitChanges();
newVirDir.Close();
iisServer.Close();
MessageBox.Show("Virtual Directory is Creatd!");
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}