Is it possible to specify the Content DB to which a site collection will belong while creating a Site Collection? I am using the SelfServiceCreateSite API. If not, is there a way to move a site collection to a specific Content DB? Can anyone please provide the code? I know both these requirements are possible in PowerShell. But I need to achieve it using Object Model.


This is an example from MSDN using SSOM.

SPWebApplication webApp = new SPSite("http://MySiteCollection").WebApplication;
SPSiteCollection siteCollections = webApp.Sites;

SPSite newSiteCollection = siteCollections.Add("sites/Site_Name", 
    "Site_Title", "Site_Description", 1033, "STS#0", 
    "DOMAIN\\Owner", "Owner_Display_Name", 
    "Owner_Email", "DOMAIN\\Contact", 
    "Contact_Display_Name", "Contact_Email",
    "Database_Server", "Database_Name", null, null);

More info in SPSiteCollection.Add method .

| improve this answer | |

PowerShell is just a wrapper for the object model.

You can create Web Template & create Sites and Site Collections from that Custom Web Template using method mentioned in below reference.

Programmatically creating Sites and Site Collections from a Custom Web Template

---------------------EXAMPLE 1-----------------------

Move-SPSite http://servername/sites/sitename -DestinationDatabase ContentDb2

This example moves the site collection http://servername/sites/sitename to the content database ContentDb2.

---------------------EXAMPLE 2-----------------------

Get-SPSite -ContentDatabase ContentDb1 | Move-SPSite -DestinationDatabase ContentDb2

This example moves all site collections in ContentDb1 to ContentDb2.

---------------------EXAMPLE 3-----------------------

Get-SPSiteAdministration | where { $_.OwnerLoginName -eq "DOMAIN\username" } | Move-SPSite -DestinationDatabase ContentDb2

This example moves all site collections where DOMAIN\username is the site collection owner to ContentDb2. The Get-SPSiteAdministration cmdlet is used instead of the Get-SPSite cmdlet because you must have permission within the site collection to access the properties of the SPSite object. You can access the properties of the SPSiteAdministration object as a SharePoint farm administrator.

---------------------EXAMPLE 4-----------------------

Move-SPSite -Identity siteUrl -DestinationDatabase databaseName -RbsProviderMapping       @{"sourceProvider1"="targetProvider1", "sourceProvider2"="targetProvider2"}

This example moves an RBS-enabled site collection from one RBS-enabled content database to another RBS-enabled content database, sourceProvider1 is the source RBS provider and targetProvider1 is the target RBS provider.

| improve this answer | |
  • Have you tried it? Is this works for you? – Hardik Jun 30 '16 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.