商業源碼熱門下載www.html.org.cn
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.windows.forms.design;
using system.directoryservices;
using system.reflection;
using system.text.regularexpressions;
//添加站點代碼
private void button2_click(object sender, system.eventargs e)
{
string newservercomment=textbox1.text;
string newserverip=textbox2.text;
string newserverport=textbox3.text;
string newserverpath=textbox4.text;
string newserverheader=textbox5.text;
//newwebsiteinfo siteinfo=new newwebsiteinfo(hostip,portnum,descofwebsite,commentofwebsite,webpath);
newwebsiteinfo siteinfo=new newwebsiteinfo(newserverip,newserverport,newserverheader,newservercomment,newserverpath);
string entpath = "iis://localhost/w3svc";
directoryentry rootentry = new directoryentry(entpath);
string newsitenum = getnewwebsiteid();
directoryentry newsiteentry = rootentry.children.add(newsitenum, "iiswebserver");
newsiteentry.commitchanges();
newsiteentry.properties["serverbindings"].value = siteinfo.bindstring;
newsiteentry.properties["servercomment"].value = siteinfo.commentofwebsite;
newsiteentry.commitchanges();
directoryentry vdentry = newsiteentry.children.add("root", "iiswebvirtualdir");
vdentry.commitchanges();
vdentry.properties["path"].value = siteinfo.webpath;
vdentry.commitchanges();
messagebox.show("站點"+siteinfo.commentofwebsite+"創建完成");
}
//iis站點查詢代碼
//// <summary>
/// get and return a new website id of specify host
/// </summary>
/// <returns>the smallest new website id of the host</returns>
public string getnewwebsiteid()
{
arraylist idlist = new arraylist();
string tmpstr;
string entrypath = "iis://localhost/w3svc";
directoryentry entry = getdirectoryentry(entrypath);
foreach (directoryentry child in entry.children)
{
if (child.schemaclassname == "iiswebserver")
{
tmpstr = child.name.tostring();
idlist.add(convert.toint32(tmpstr));
}
}
idlist.sort();
int i = 1;
foreach (int id in idlist)
{
if (i == id)
{
i++;
}
}
return i.tostring();
}
//刪除站點代碼
private void button3_click(object sender, system.eventargs e)
{
string newservercomment=textbox1.text;
string newserverip=textbox2.text;
string newserverport=textbox3.text;
string newserverpath=textbox4.text;
string newserverheader=textbox5.text;
string newserverhost=textbox6.text;
string sitenum = getwebsitenum(newservercomment);
string rootpath = "iis://localhost/w3svc";
string siteentpath =rootpath+"/"+sitenum;
directoryentry rootentry = getdirectoryentry(rootpath);
directoryentry siteentry = getdirectoryentry(siteentpath);
rootentry.children.remove(siteentry);
rootentry.commitchanges();
messagebox.show("站點 "+newservercomment+" 刪除完畢");
}
//根據站點名稱獲取站點標識符
#region 獲取一個網站編號的方法
public string getwebsitenum(string sitename)
{
regex regex = new regex(sitename);
string tmpstr;
string entpath = "iis://localhost/w3svc";
directoryentry ent =new directoryentry(entpath);
foreach(directoryentry child in ent.children)
{
if(child.schemaclassname == "iiswebserver")
{
if(child.properties["serverbindings"].value != null)
{
tmpstr = child.properties["serverbindings"].value.tostring();
if(regex.match(tmpstr).success)
{
return child.name;
}
}
if(child.properties["servercomment"].value != null)
{
tmpstr = child.properties["servercomment"].value.tostring();
if(regex.match(tmpstr).success)
{
return child.name;
}
}
}
}
return "";
}
#endregion
#region 新iis站點信息結構體
public struct newwebsiteinfo
{
private string hostip; // the hosts ip address
private string portnum; // the new web sites port.generally is "80"
private string descofwebsite; // 網站表示。一般為網站的網站名。例如"www.dns.com.cn"
private string commentofwebsite;// 網站注釋。一般也為網站的網站名。
private string webpath; // 網站的主目錄。例如"e:/tmp"
public newwebsiteinfo(string hostip, string portnum, string descofwebsite, string commentofwebsite, string webpath)
{
this.hostip = hostip;
this.portnum = portnum;
this.descofwebsite = descofwebsite;
this.commentofwebsite = commentofwebsite;
this.webpath = webpath;
}
public string bindstring
{
get
{
return string.format("{0}:{1}:{2}", hostip, portnum, descofwebsite);
}
}
public string commentofwebsite {get{return commentofwebsite;}}
public string webpath {get{return webpath;}}
}
#endregion
新聞熱點
疑難解答