Programmatically provision hostheader site collection (MOSS/Sharepoint 2007)

Programmatically provision hostheader site collection (MOSS/Sharepoint 2007)

I was looking for a sample on creating a Host header based site collection (programmatically) i.e. using WSS/Sharepoint 2007 API and came across the msdn article, but there is no sample:


We can easily do it thru STSADM:

stsadm -o createsite -url http://THE-HOST-HEADER-FOR-THE-SITE-COLLECTION -ownerlogin DOMAIN\username -owneremail -hhurl http://THE-URL-OF-THE-WEBAPPLICATION-THE-SITE-COLLECTION-IS-GOING-INTO

 But then I got the sample, thought of sharing this with a larger community in case if someone wants to do it:


SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://the-url-of-the-webapplication-the-site-collection-is-going-into"));



                "http://the-host-header-for-the-site-collection", // site URL

                "The Site Title", // site title

                "The Site Description", // site description

                1033, // site LCID that represents the language, e.g. 1033 = en-US

                "STS#0", // site template, e.g. STS#0 = Team Site

                @"DOMAIN\username", // site owner login

                "Firstname Lastname", // site owner name

                "", // site owner e-mail address

                NULL, // secondary owner login

                NULL, // secondary owner name

                NULL, // secondary owner e-mail address

                true); // is this a host-named site collection

Comments (1)
  1. vijay says:

    How would i get the ownerlogin, owneremail from my spwebapplication object to pass to Sites.Add function?

    I want to use the same user who created the webapp.

Comments are closed.

Skip to main content