Udostępnij za pośrednictwem


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: https://msdn.microsoft.com/en-us/library/ms479602.aspx

 

We can easily do it thru STSADM:

stsadm -o createsite -url https://THE-HOST-HEADER-FOR-THE-SITE-COLLECTION -ownerlogin DOMAIN\username -owneremail username@domain.com -hhurl https://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("https://the-url-of-the-webapplication-the-site-collection-is-going-into"));

 

webApp.Sites.Add(

                "https://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

                "username@domain.com", // 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

  • Anonymous
    June 22, 2010
    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.