Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
    
Related question: sharepoint.stackexchange.com/questions/12300/… –  Kit Menke May 26 '11 at 14:36
    
@kit-menke Programmatically solution please "SharePoint object model" –  Mahmoud May 26 '11 at 14:42
    
@markov00 - you can call stsadm extensions r powershell whatetever programatically. Whats you're aversion to doing this? –  Ryan May 26 '11 at 15:52
    
@Ryan any exemple please ?! –  Mahmoud May 26 '11 at 15:56
1  
How about "How can I run another application or batch file from my c# code"? blogs.msdn.com/b/csharpfaq/archive/2004/06/01/146375.aspx –  Ryan May 28 '11 at 11:25
show 2 more comments

4 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
Or simply use the export and import STSADM commands: technet.microsoft.com/en-us/library/… –  Kit Menke May 26 '11 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 '11 at 14:36
    
@kit-menke Programmatically solution please "SharePoint object model" –  Mahmoud May 26 '11 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 '11 at 15:15
    
@Bil-Simer i was talking about import/export using object model not PS command. –  Mahmoud Jun 1 '11 at 7:51
show 1 more comment

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();
share|improve this answer
add comment

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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