/// <summary>
        /// Check if a website on the given server exist.
        /// Check on websitename (ServerComment) is case insensitive.
        /// </summary>
        /// <param name="serverName">Name of the IIS server e.g. localhost</param>
        /// <param name="websiteName">Name of the website e.g. test</param>
        /// <returns></returns>
        public bool DoesWebsiteExist(string serverName, string websiteName)
        {
            bool result = false;

            DirectoryEntry w3svc = new DirectoryEntry(string.Format("IIS://{0}/w3svc", serverName));

            foreach (DirectoryEntry site in w3svc.Children)
            {
                if (site.Properties["ServerComment"] != null)
                {
                    if (site.Properties["ServerComment"].Value != null)
                    {
                        if (string.Compare(site.Properties["ServerComment"].Value.ToString(), websiteName, false) == 0)
                        {
                            result = true;
                        }
                    }
                }
            }

            return result;
        }

2 Comments

  1. Hey are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and create my own.
    Do you require any html coding expertise to make your own blog?

    Any help would be greatly appreciated!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.