You need to have the admin rights to use Stsadm utility. Usually archiving functionalities will be doing by a Sharepoint administrator only. The import, export backup and recovery command are available to do this for site and web via Stsadm.
The export and import using the object model is alternate way to do the Archival of site collection or web in Sharepoint. SPExport object creates a
Sample code for Export
//set the export object
SPExportObject exportObject = new SPExportObject();
exportObject.Id = resourceWeb.ID;
exportObject.IncludeDescendants = SPIncludeDescendants.All;
exportObject.Type = SPDeploymentObjectType.Web;
//export settings
SPExportSettings exportsettings = new SPExportSettings();
exportsettings.SiteUrl = resourceSite.Url;
importSettings.IncludeSecurity = SPIncludeSecurity.All; //(if you need to include //security whileimport)
exportsettings.BaseFileName = <.cmp file name>
exportsettings.OverwriteExistingDataFile = true;
exportsettings.ExportMethod = SPExportMethodType.ExportAll ;
exportsettings.FileLocation =
exportsettings.IncludeSecurity = SPIncludeSecurity.None ; // no security settings will be imported
exportsettings.FileCompression = true;
exportsettings.ExcludeDependencies = true;
exportsettings.ExportObjects.Add(exportObject);
// export
SPExport export = new SPExport(exportsettings);
export.Run();
Sample code for Import
// import settings
SPImportSettings importSettings = new SPImportSettings();
importSettings.SiteUrl = siteUrl;
importSettings.BaseFileName = <.cmp file name>
importSettings.FileLocation = <.cmp file location>
importSettings.IncludeSecurity = SPIncludeSecurity.All;
// to make the security importing need to set the following property
importSettings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll;
importSettings.RetainObjectIdentity = false;
//import
SPImport import = new SPImport(importSettings);
import.Run();
We need to do disable FormDigestSettings property of SPWebApplication. Before we do an export /import and enable the same after, at both the source and at the target application.Note that in the above example we are not using SPImportObject since what ever will be exported to the
Unlike Archiving using stsadm command can be executed by those having Admin rights,
by using the object model for archiving, archiving can be done any user who has rights to run the code with elevated privileges. One more way to do archiving in share point is by using Sites.asmx web service’s ImportWeb and ExportWeb Services. But the limitation here is that this method are limited to the webs rather than the site collection and need to call for each spwebs in the site collection in an iterative way and is time consuming.
No comments:
Post a Comment