10

I am looking for a C# script that will move a site with all permissions and content to another site collection. Google isn't helping me or maybe i dont know what exactly to look for.

e.g.

I have a site

usa3001.abcd.com\sites\mysite1 . . . usa3001.abcd.com\sites\mysite103

I want to create a new site collections , it should move all everything e.g. content and permissions

usa3001.abcd.com\mysite1 . . . usa3001.abcd.com\mysite102

I know I can use stsadm to export it and import it but that gonna take too much time and effort for support time and they wont know whats happening.

  • Why do you need a C# script when this can be easily done through stsadm. – ArkoD Jul 13 '12 at 10:41
  • because i have hundreds of sites to be moved to new site collection – Muhammad Raja Jul 13 '12 at 10:42
  • i updated my question :) – Muhammad Raja Jul 13 '12 at 10:47
  • So write a script that calls STSADM commands? – Kit Menke Jul 13 '12 at 15:59
3

For a single site (SPWeb) try using the content migration APIs. http://msdn.microsoft.com/en-us/library/ms453426.aspx

SPExportObject exportObject = new SPExportObject();

and i've been successful with these settings:

            SPExportSettings settings = new SPExportSettings();
            settings.FileCompression = false;
            settings.ExportMethod = SPExportMethodType.ExportAll;
            settings.IncludeSecurity = SPIncludeSecurity.All;
            settings.IncludeVersions = SPIncludeVersions.All;
            settings.HaltOnWarning = false;
            settings.ExcludeDependencies = false;

For site collections you can do SPSiteCollection.Backup and SPSiteCollection.Restore:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spsitecollection.backup

        SPWebApplication webApp = SPWebApplication.Lookup("http://url");
        SPSiteCollection siteCollections = webApp.Sites;
        siteCollections.Backup(,,);
2

Exporting a site should grab all the subsites as well. I just did that this week by exporting an entire site collection and importing it as a subsite within an existing site collection. Every subsite in the source site made it to the destination site.

I use:

stsadm -o export -url http://domain/sites/site -filename c:\temp\site.dat -nofilecompression -includeusersecurity -versions 4

and

stsadm -o import -url http://domain/sites/newsite/subsite -filename c:\temp\site.dat -nofilecompression -includeusersecurity 
  • I tried that BEFORE but I am getting error, here is link for that question sharepoint.stackexchange.com/questions/40925/… – Muhammad Raja Jul 13 '12 at 12:01
  • I don't think you want to use export/import for a site collection. You would use backup/restore for a site collection. – Kit Menke Jul 13 '12 at 15:58
  • In this case, it was to export a site collection to import as a subsite in another site collection. Backup and restore works if you need it to be a different top level collection but doesn't work properly if doing it as a subsite. – Eric Alexander Jul 13 '12 at 16:28
  • I have just a site with tens of subsites and more subsites in it, and I want to add this site to another site collection, I tried Import & export but I am getting error for that, and not sure if backup will get me everything, i tried to back up using central administration but i guess thats only for web applications and site collections in sharepoint 2007 – Muhammad Raja Jul 16 '12 at 8:23
  • First of all backup the site collection using stsadm -o backup and restore it to the new location /sites/mysitexyz and then use the content and strucutre to move the sites from sub-locations to top locations and then delete the parent webs. You can also use SharePoint designer backup and restore subsites(not site collection) if they are small sites. I trust more to SP designer than import/export cmd as it works well for me compare to import/export. – user994521 Jul 20 '12 at 1:20
1

Great question!

I found this article to be a good resource for me on this topic: http://msdn.microsoft.com/en-us/library/ms438819.aspx

(Content Migration object model, the most flexible option)

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.