MEA Center of Expertise

We are a 120+ technology enthusiasts helping Microsoft customers around Middle-East & Africa region. We bridge Microsoft tools & technologies to their businesses.

Creating a host-named site collection programmatically

Creating a host-named site collection programmatically

  • Comments 2
  • Likes

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 URL http://training.sharepoint.com in the SharePoint Server 2010 Web application with the URL http://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

Comments
  • Hi,

    I want to create a new site collection named " training.sharepoint.com/.../IT"

    Kindly guide how to acheiev this via c# code.

  • Hi Ayman,

    I am trying to create content database through C#.
    Kindly tell which class to use create content database.

    Regards,
    Gaurav

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment