Creating Site Collection




Go back to index

How to create site collection


Following code block explains how to programmatically create a site collection in a web application.

      using System;
      using SPTool.Library;
      using System.Collections.ObjectModel;
 
      namespace SPTool.Test
      {
          class Program
          {
              static void Main(string[] args)
              {
                  SPTWebApplication webApplication = new SPTWebApplication("http://sptool/");

                  // Create Site Collection
                  SPTReturn returnObj = webApplication.CreateSiteCollection("/", @"Domain\AdminUser", "");
                  // Creating a site collection with a Template
                  //SPTReturn returnObj = webApplication.CreateSiteCollection("LFEM", "Learn from every moment", "/blogs/LFEM", "SPS#0", @"Domain\AdminUser", "", "", 0);

                  // Check the status of site collection creation
                  if (returnObj.State == SPTState.Success)
                  {
                      // Successfully created site collection
                  }
                  else
                  {
                      // Creating site collection failed
                  }
              }
          }
      }
      


Go back to index