Creating a host-named site collection programmatically

A host header is a third piece of information that you can use in addition to the IP address and port number to uniquely identify a Web domain or, as Microsoft calls it, an application server.

In SharePoint 2010, You can apply host headers at two different levels :

  • The Web application (IIS Web site) level
  • The site collection level

The following code snippet programmatically creates the host-named site collection with the URLhttp://training.sharepoint.com in the SharePoint Server 2010 Web application with the URLhttp://sharepoint

SPWebApplication webApp = SPWebApplication.Lookup(new
Uri(“http://sharepoint“));
SPSiteCollection sites = webApp.Sites;
SPSite Site = sites.Add(“http://training.sharepoint.com”, “Training”,
“Training Site”, 1025, “STS#0”, “domain\ayman”,
“Ayman El-Hattab”, “ayman@aymanelhattab.com”, “domain\marwan”,
“Marwan Tarek”, marwan@marwantarek.net, true);

You can also use PowerShell to achieve the same results, for more info refer to :http://technet.microsoft.com/en-us/library/cc424952.aspx

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s