0

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));
                    }
                );
  • can you please post your code here.? – Karthik Jaganathan Nov 21 '13 at 16:11
  • Code added to the question. – alykhalid Nov 22 '13 at 8:35
1

Please change

targetListItem.set_item('FileLeafRef', NEW_FILE_NAME); 

to

targetListItem.set_item('BaseName', NEW_FILE_NAME); 
  • 1
    I am sorry but that does not work. – alykhalid Nov 29 '13 at 8:37
  • I'm tested this in sharepoint 2010 and this works. – Andrey Ungur Nov 29 '13 at 8:45
  • That is strange, could this have been changed in 2013 ? – alykhalid Nov 29 '13 at 8:47
  • Unfortunately can't check this. – Andrey Ungur Nov 29 '13 at 8:52
1

In order to change file name including file extension you need to use either copyTo or moveTo on the SP.File object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.