I am updating a file in document library using a Put request from the client side. I need to know, how to change the file name after the file has been updated. My upload code is working fine. I can change other properties/metadata fields but not the file name.
for uploading files I am using code from http://www.shillier.com/
WingtipToys.Rest.Libs.upload(LIBRARY_NAME, File_Name, File_Object) // upload file
.then(Function (data) {
//Update the file name property by getting the file by DOCID
var cc = new SP.ClientContext();
var targetList = cc.get_web().get_lists().getByTitle('LIBRARY_NAME');
var targetListItem = targetList.getItemById(SP_DOCID);
targetListItem.set_item('FileLeafRef', NEW_FILE_NAME); //DOES NOT WORK
targetListItem.update();
cc.executeQueryAsync(function (data) {
console.log('Item updated!');
},
function (sender, args) {
alert(JSON.stringify(err));
});
alert("Update successfully");
},
function (err) {
alert(JSON.stringify(err));
}
);