Sharepoint 2010 Client Object Model - Upload Document (409 Conflict)

前端 未结 4 1145
花落未央
花落未央 2021-02-04 16:53

I am using the SP2010 Client Object Model to upload to a document library, following the lead from Microsoft here: http://msdn.microsoft.com/en-us/library/ee956524.aspx#SP2010Cl

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 17:22

    In my case the file was uploaded using SaveBinaryDirect into a library with versioning turned on. If the file is not checked in, any subsequent attempts to upload a newer version will result in the 409 error. Make sure to check-in after upload in when versioning is turned on.

        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();
    

提交回复
热议问题