4

Since we can't save SharePoint site (with publishing feature enabled) as Template, I'm looking for a way to do this programmatically :

Make a copy of "SiteA" with a new name "SiteB" under the same SiteCollection

http://SPServer/Collection/SiteA

http://SPServer/Collection/SiteB

7

4 Answers 4

2

I think the easiest way is to do an export followed by an import. That should work without the duplicate GUID problem. PowerShell cmdlets are Export-SPWeb and Import-SPWeb.

Programmatically, there are equivalents to these in the Content Migration API (sometimes known as "PRIME"). These are in the Microsoft.SharePoint.Deployment Namespace. You use the SPExport class to export a content migration package, and then SPImport to do the import.

There is an overview of content migration on MSDN. Don't forget that you can also use the web services API, as a programmatic alternative to the object model.

6
  • Or simply use the export and import STSADM commands: technet.microsoft.com/en-us/library/…
    – Kit Menke
    May 26, 2011 at 14:36
  • @SPDoctor Yes i allready try this way but i cant get what i need. if siteB existe i get SPServer/Collection/SiteB/SiteA if i provide the rootURL SPServer/Collection the new site is not created.
    – Mahmoud
    May 26, 2011 at 14:36
  • @kit-menke Programmatically solution please "SharePoint object model"
    – Mahmoud
    May 26, 2011 at 14:38
  • SPDoctors answer should be marked as the answer based on your original question of making a copy SiteA to SiteB. In your original URLs Export/Import will work fine. In your response you say "if siteB exist[e] i get SPServer/Collection/SiteB/SiteA". If you did the export/import you would not get this. Please provide the exact PS command you're using.
    – Bil Simser
    May 31, 2011 at 15:15
  • @Bil-Simer i was talking about import/export using object model not PS command.
    – Mahmoud
    Jun 1, 2011 at 7:51
1

The Rayn's solution (see post comments) gived me an idea to run PowerShell Cmdlt from my code using :

System.Management.Automation

Collection<String> results = PowerShell.Create().AddScript(Ps).Invoke<String>();

but i still have a problem:

running this cmd "Get-Process" : i got the result.

running this cmd "Import-SPWeb -Identity http://SPserver/CollA/SiteA -Path c:\bkp\file.cmp" :

The term 'Import-SPWeb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

running the second cmd on powershell window cause no problem and i got my site imported.

Solution :

string BkpFile = @"C:\File.cmp";
string Url = "http://SPServer/CollA/SiteA";
string PsImport = "Import-SPWeb –Identity " + Url + " -Path " + BkpFile;
string PsPssnaping = "Add-PSSnapin Microsoft.SharePoint.PowerShell";

PowerShell ps = PowerShell.Create();

ps.AddScript(PsPssnaping);
ps.AddScript(PsImport);
ps.Invoke();
1

Is there no possibility to Duplicate a present working site to with another name ? The reason being i would like to make changes to our Prod site and would like to test the changes on a test site for which i would need to replicate our prod site ..

Thanks

0

There is a reason Microsoft has restricted this and they are not clear about it, I faced the same issue and found that

-> Its a Object Cache issue as it uses same GUIDS

One workaround to make a copy in the same webapp is to restore the site collection into different content DBs ( like make the current content DB offline , add a new content DB and restore) , I have not tested this properly but I think the Object cache issues will be there.

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.