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));
                    }
                );
2
  • can you please post your code here.? Commented Nov 21, 2013 at 16:11
  • Code added to the question.
    – Ali Khalid
    Commented Nov 22, 2013 at 8:35

2 Answers 2

1

Please change

targetListItem.set_item('FileLeafRef', NEW_FILE_NAME); 

to

targetListItem.set_item('BaseName', NEW_FILE_NAME); 
4
  • 1
    I am sorry but that does not work.
    – Ali Khalid
    Commented Nov 29, 2013 at 8:37
  • I'm tested this in sharepoint 2010 and this works. Commented Nov 29, 2013 at 8:45
  • That is strange, could this have been changed in 2013 ?
    – Ali Khalid
    Commented Nov 29, 2013 at 8:47
  • Unfortunately can't check this. Commented Nov 29, 2013 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 and acknowledge you have read our privacy policy.

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