CSOM upload file multiple versions
Recently my colleague had a problem with multiple versions being created while trying to upload file via CSOM and setting the metadata fields. Problem is that this is a two-step process. Using SSOM it would be fairly easy to upload and modify data with one update, but with the client side object model the file must exist beforehand we modify its data. There’s a possible workaround to create just one version using check-in method. Below code snippet demonstrates how CheckOut and CheckIn allow to upload and modify file in one process. public void UploadDocumentContentStream(ClientContext ctx, string libraryName, string filePath) { Web web = ctx.Web; using (var fs = new FileStream(filePath, FileMode.Open)) { var flciNewFile = new FileCreationInformation { ContentStream = fs, Url = Path.GetFileName(filePath), Overwrite = true }; List docs = web.Lists.GetByTitle(libraryName); Microsoft.SharePoint.Cl...