DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

[IIs6] Create New Site

03.19.2012
| 1863 views |
  • submit to reddit
        // description of your code here

using System;
using System.DirectoryServices;

namespace IIs_Programming
{
    class IIs6_CreateSite
    {
        public static int CreateWebsite(string webserver, string serverComment, string serverBindings, string homeDirectory)
        {
            DirectoryEntry w3svc = new DirectoryEntry("IIS://localhost/w3svc");

            //Create a website object array
            object[] newsite = new object[] { serverComment, new object[] { serverBindings }, homeDirectory };

            //invoke IIsWebService.CreateNewSite
            object websiteId = (object)w3svc.Invoke("CreateNewSite", newsite);

            return (int)websiteId;
        }

        public static void Main(string[] args)
        {
            int siteId = CreateWebsite("localhost", "Testing.net", ":8080:Testing.net", "C:\\inetpub\\wwwroot");
            //DirectoryEntry newSite = new DirectoryEntry("IIS://localhost/w3svc/" + siteId);
            //newSite.Invoke("Start", null);
            Console.WriteLine("Created website with ID: " + siteId);
            Console.ReadLine();
        }


    }
}