3

I have downloaded a document file (current version) and its version history files (old version files) from one of my sharepoint site list. Now, I want to upload that current version file into another site list. After uploading the current version file, I need to upload its version files into _vti_history folder and update version information in current version file.

I can upload the current version file by using below csom code:

using (var clientContext = new ClientContext(url))
{
     using (var fs = new FileStream(fileName, FileMode.Open))
     {
         var fi = new FileInfo(fileName);
         var list = clientContext.Web.Lists.GetByTitle(listTitle);
         clientContext.Load(list.RootFolder);
         clientContext.ExecuteQuery();
         var fileUrl = String.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, fi.Name);
     Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl, fs, true);
 }

}

But, I don't know how to upload the version file and update version info in actual file.

Can anyone help me to achieve this in C# using csom?

0

I have the same question, but after some thought and research, the only way I can think to accomplish this is by the following (I haven't tested this yet): (1) Get the file versions from the other site as you have already done. (2) Enable versioning on the target library where you can upload the current version. (3) iterate through each version of the file, getting the binary using File.OpenBinaryStream() (4) use File.SaveBinaryDirect for the version - updating any existing file. (5) Check in the file - if a major version use CheckinType.MajorCheckIn, if minor, use CheckinType.MinorCheckIn. Once done iterating through each version, you will have copied the full version history in the correct order for the file and you can use File.SaveBinaryDirect on the current version file. It is a similar approach to what I found here: Copy Documents from file share to SPO DocLib with versions using PowerShell

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.