Del site

  string SiteID = null;
            DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");
           
                foreach (DirectoryEntry child in root.Children)
                {
                    if (child.SchemaClassName == "IIsWebServer")
                    {
                        if (WebSiteName == child.Properties["servercomment"].Value.ToString())
                        {
                             SiteID = child.Name.ToString();
                        }
                    }
                }          
            try
            {
                if (SiteID == null) return "error:该站点不存在.";

                DirectoryEntry deRoot = new DirectoryEntry("IIS://localhost/W3SVC");
                try
                {
                    DirectoryEntry deVDir = new DirectoryEntry();
                    deRoot.RefreshCache();
                    deVDir = deRoot.Children.Find(SiteID, "IIsWebServer");
                    deRoot.Children.Remove(deVDir);

                    deRoot.CommitChanges();
                    deRoot.Close();
                    return "successful:删除站点" + WebSiteName + "成功!";
                }
                catch (System.Exception)
                {
                    return "error:该站点不存在.";
                }
            }
            catch (Exception e)
            {
                return "error:删除站点失败." + e.Message;
            }

posted @ 2010-08-05 00:31  greencolor  阅读(324)  评论(0编辑  收藏  举报