I'd like to create a site collection from a custom application page in central admin. The administrator needs the option to specify an existing, mounted content database to store the new site collection. I'm running SharePoint Foundation 2010.
Creating a site collection with PowerShell allows an existing mounted content database to be specified, but none of the SPSiteCollection.Add()
object model overloads allow the same. I can create a new database, but not specify an existing database.
Browsing the Microsoft.SharePoint.PowerShell assembly with Reflector shows the New-SPSite
cmdlet uses an additional, internally scoped SPSiteCollection.Add()
overload that includes a content database parameter. I assume the Microsoft.SharePoint.PowerShell assembly is listed in an InternalsVisibleToAttribute in the Microsoft.SharePoint assembly, allowing PowerShell access to the internal function while remaining hidden to my code.
I'm aware that I can execute PowerShell scripts from C#, is there any reason not to do this by calling the New-SPSite
cmdlet from code? Is there any other method I've missed?