title: Creating site collection programmatically with custom site template in Office 365 APP
body: <p>I am trying to create a site collection in Office 365 through an auto-hosted app. I am using the Microsoft.Online.SharePoint.Client.Tenant.dll and my code is as below.</p>
  
  <pre><code>using System;
  using Microsoft.Online.SharePoint.TenantAdministration;
  using Microsoft.SharePoint.Client;
  using System.Security;
  
  namespace SharePoint123
  {
   class Program
   {
      static void Main(string[] args)
      {
          //please change the value of user name, password, and admin portal URL
          string username = "xxxx@xxxx.onmicrosoft.com";
          String pwd = "xxxx";
          ClientContext context = new ClientContext("https://xxxx-admin.sharepoint.com");
          SecureString password = new SecureString();
          foreach (char c in pwd.ToCharArray())
          {
              password.AppendChar(c);
          }
          context.Credentials = new SharePointOnlineCredentials(username, password);
  
          Tenant t = new Tenant(context);
          context.ExecuteQuery();//login into SharePoint online
  
  
          //code to create a new site collection
          var newsite = new SiteCreationProperties()
          {
              Url = "https://xxxxx.sharepoint.com/sites/createdbyProgram1",
              Owner = "xxxxx@xxxxx.onmicrosoft.com",
              Template = "STS#0", //using the team site template, check the MSDN if you want to use other template
              StorageMaximumLevel = 100,
              UserCodeMaximumLevel = 100,
              UserCodeWarningLevel = 100,
              StorageWarningLevel = 300,
              Title = "CreatedbyPrgram",
              CompatibilityLevel = 15, //15 means Shapoint online 2013, 14 means Sharepoint online 2010
  
          };
          t.CreateSite(newsite);
  
          context.ExecuteQuery();
          //end 
  
      }
    }
  
  }
  </code></pre>
  
  <p>However, I would like to use a custom site template that I have created, instead of the "STS#0" team site template. The custom site template exists in the Solution Gallery of the site collection in which my APP is deployed. Is there a way I can upload this site template and activate it, during the creation of the new site collection programmatically?</p>