In my recent project I need to create virtual directory in IIS programmatically. I was searching on net and found a really good article posted by Dipali Choksi. You can find the artilce here. I have copied that article below for my reference.
Using System.DirectoryServices;
private void btnCreateDirectory_Click(object sender, EventArgs e)
{
string strSchema = "IIsWebVirtualDir";
string strRootSubPath = "/W3SVC/1/Root" ;
// you can specify any server name , "localhost" is for example
DirectoryEntry deRoot =
new DirectoryEntry("IIS://" + "localhost" + strRootSubPath);
try
{
deRoot.RefreshCache();
DirectoryEntry deNewVDir =
deRoot.Children.Add("Name of Virtual Directory", strSchema);
deNewVDir.Properties["Path"].Insert(0, "Path for Virtual Directory");
deNewVDir.CommitChanges();
deRoot.CommitChanges();
// Create a Application
if (strSchema == "IIsWebVirtualDir")
deNewVDir.Invoke("AppCreate", true);
// Save Changes
deNewVDir.CommitChanges();
deRoot.CommitChanges();
deNewVDir.Close();
deRoot.Close();
lblResult.Text = "Virtual Directory "
+ ("Name of Virtual Directory"+ "(" + "Path for Virtual
Directory" + ") has been created";
}
catch (Exception ex)
{
lblResult.Text = ex.Message;
}
}
4 comments:
Hi All,
I found a really cool article on same here.
http://www.west-wind.com/WebLog/posts/399.aspx
http://www.15seconds.com/issue/010710.htm
THanks.
Thank you very much....
Very Informative blog thank you for sharing. Keep sharing.
Best software training institute in Chennai. Make your career development the best by learning software courses.
rpa course in chennai
power bi training in chennai
uipath training in chennai
Thanks a lot very much for the high quality and results-oriented help.
I won’t think twice to endorse your blog post to anybody who wants
and needs support about this area.
mysql dba online training in Chennai
Unix classes in Chennai
Best IT training institute in Chennai
Post a Comment