Friday, September 19, 2008

Programatically exporting item version and properties


string webUrl = workflowProperties.Web.Url;
SPListItem item = workflowProperties.Item;

// Create an object for the record to transfer.
SPExportObject exportObject = new SPExportObject();
exportObject.Type = SPDeploymentObjectType.ListItem;
exportObject.Url = webUrl + "/" + item.Url;

// Set the export settings.
SPExportSettings exportSettings = new SPExportSettings();
exportSettings.ExportMethod = SPExportMethodType.ExportAll;
exportSettings.IncludeSecurity = SPIncludeSecurity.All;
exportSettings.IncludeVersions = SPIncludeVersions.All;

exportSettings.AutoGenerateDataFileName = false;
exportSettings.BaseFileName = item.Name + ".cab";
exportSettings.SiteUrl = webUrl;
exportSettings.FileLocation = transferLocation;
exportSettings.ExportObjects.Add(exportObject);

// Export the record.
SPExport export = new SPExport(exportSettings);
export.Run();

// Write transfer event to audit log.
item.Audit.WriteAuditEvent("Record Transfered");

0 comments: