I have a .bak file of a SharePoint site. I want to restore it back. I am doing this with below code:

var targetSiteCollection = webApp.Sites;

targetSiteCollection.Restore(this._siteUrl, backupFilename, true, true);

Its working fine. But if I want to restore to a specific content DB, that option am not getting here. However its possible with PowerShell SSOM where we can just pass the content DB name. Is there any available option in C# SSOM also to do so?

Thanks in advance!!!!

1 Answer 1


Somehow I found a work around here. There is no direct way to restore the SharePoint site to a specific content database, But we can move the site to the specific database once it is restored successfully. For this we have to do this:

using (var site = new SPSite(siteUrl))
            var sitesToMove = new List<SPSite>
            site.ContentDatabase.Move(targetDb, sitesToMove, out var failedSites);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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