Welcome to MSDN Blogs Sign in | Join | Help

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

 

We can easily do it thru STSADM:

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

 But then I got the sample, thanks again to TROY STARR he is a great help, 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"));

 

webApp.Sites.Add(

                "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

                "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

Published Tuesday, May 05, 2009 11:09 PM by ketaanhs

Comments

# Programmatically provision hostheader site collection (MOSS/Sharepoint 2007) | ASP NET Hosting

# re: Programmatically provision hostheader site collection (MOSS/Sharepoint 2007)

Thursday, June 11, 2009 7:25 PM by yadnesh

Hi ketan,

Your blog is very much helpful. But i am facing a little issue this.

I am trying to make publishing site collection (hostheader) using site template : BlankInternateContainer#0". while using this and running application it throws file not found exception. Site can not be provisioned properly.

But strange thing i observed is, it works for normal site collection.

Please advise.

Thanks!!

Yadnesh

yadnesh.cts@gmail.com

# re: Programmatically provision hostheader site collection (MOSS/Sharepoint 2007)

Thursday, June 11, 2009 7:34 PM by yadnesh

there is a little spelling mistakeBlankInternetContainer#0

Thanks!!

# re: Programmatically provision hostheader site collection (MOSS/Sharepoint 2007)

Thursday, June 18, 2009 11:45 AM by ketaanhs

@Yadnesh: I have created a HH site collection using above code and works great for me. Please check your environment and if you can run STSADM -o CreateSite on that to provision the site collection (HostHeader).

Anonymous comments are disabled
 
Page view tracker