Hi, i'm uploading a file to a doc library with javscript jsom in Sharepoint 2013. This doc library has versioning enabled. The problem is that the upload creates two history records in the doc's versioning. I suspect that one is caused for uploading the doc and the other one for editing it's properties. I want to avoid that, my code is like this:
var clientContext; var oWebsite; var oList; var fileCreateInfo; var fileContent; clientContext = new SP.ClientContext.get_current(); oWebsite = clientContext.get_web(); oList = oWebsite.get_lists().getByTitle("ALibrary"); fileCreateInfo = new SP.FileCreationInformation(); fileCreateInfo.set_url("asd" + idInterno +".pdf"); fileCreateInfo.set_content(new SP.Base64EncodedByteArray()); fileCreateInfo.set_overwrite(true); var byteArr = new Uint8Array(reader.result); for (var i = 0; i < byteArr.length; i++) { fileCreateInfo.get_content().append(byteArr[i]); } this.newFile = oList.get_rootFolder().get_files().add(fileCreateInfo); this.newFile.get_listItemAllFields().set_item("AProperty1",myproperty1); this.newFile.get_listItemAllFields().set_item("AProperty2",myproperty2);
this.newFile.get_listItemAllFields().update(); clientContext.load(this.newFile); clientContext.executeQueryAsync( Function.createDelegate(this, successOtroHandler), Function.createDelegate(this, errorOtroHandler) );