I am trying to create a functionality of transfering the Document set with all its history to another library in the same site. My implementation on reproducing the history of single document is based very much on https://julieturner.net/2011/06/maintain-file-version-history-when-movingcopying-files-between-sharepoint-sites/, but somehow modified to my environment with minor/major versioning enabled. To create a major version I use File.Approve method, but this sets the last modified date of newly created major version. I have tried to do UpdateOverwriteVersion, SystemUpdate, SystemUpdate(false) to update the version data, but failed to modify date or created unnecessary minor version. Is there any way to restore the date when the document version was created in environment where major/minor versioning is enabled?
1 Answer
I am not aware of which version of SharePoint you are using. But the CSOM has a functionality called MoveTo. Which moves the files as well as preserves the metadata information.
context.Site.CreateCopyJobs(new string[] { "sourceurl1","sourceurl2" },
"destinationurl", new CopyMigrationOptions()
{
IsMoveMode = true,
IgnoreVersionHistory = false,
AllowSchemaMismatch = true,
NameConflictBehavior = MigrationNameConflictBehavior.Replace
});
context.ExecuteQuery();
Note: To prevent loss of data make sure the version settings and the library schema matches at both source and destination.
-
I appreciate your proposal, but all other code is written in using server side methods. Also, I have to migrate a document history up to a certain document version, create a snapshot for a document set and than continue with version transfer.– FurliJul 2, 2020 at 9:25