在我的情况下,文件是使用 SaveBinaryDirect 上传到打开版本控制的库中。如果未签入该文件,则任何后续尝试上传较新版本都将导致 409 错误。确保在打开版本控制后在上传后签入。
var clientContext = (ClientContext)file.Context;
destinationWebContext.Load(destinationList, d => d.ParentWebUrl);
destinationWebContext.Load(destinationList, d => d.RootFolder.ServerRelativeUrl);
clientContext.Load(file, f => f.ServerRelativeUrl);
clientContext.Load(file, f => f.Name);
if (clientContext.HasPendingRequest)
clientContext.ExecuteQueryRetry();
if (destinationWebContext.HasPendingRequest)
destinationWebContext.ExecuteQueryRetry();
var location = string.Format("{1}/{2}", destinationList.ParentWebUrl, destinationList.RootFolder.ServerRelativeUrl, file.Name);
var fileInfo = File.OpenBinaryDirect(clientContext, file.ServerRelativeUrl);
File.SaveBinaryDirect(destinationWebContext, location, fileInfo.Stream, overwrite);
File newFile = destinationWebContext.Web.GetFileByServerRelativeUrl(location);
newFile.CheckIn("Checked in by provisioning service", Microsoft.SharePoint.Client.CheckinType.MajorCheckIn);
destinationWebContext.ExecuteQuery();