0

I am trying to Move folder to different location within Document library using REST API. What i have done is:- I have created SharePoint add-in through which i want to move folder from one location to another location in SharePoint Document Library.

Is there any method similar to "moveto()" method Specified here for moving folder or any other way to do the same using REST API.

thanks in advance

8
  • I haven't had much luck moving a folder in the past, but is there any reason you wouldn't just create a new folder instead?
    – Morten K
    Commented Sep 19, 2018 at 11:53
  • Actually that folder contain files, So if I create new folder I have to re-upload all files into that folder, which will require more time. Commented Sep 19, 2018 at 12:17
  • Ah yeah i see. To be honest I don't think you can move folders including content though.
    – Morten K
    Commented Sep 19, 2018 at 12:18
  • Manually we can do that, So there should exist some API to do the same. Commented Sep 19, 2018 at 12:45
  • are you ok with jsom to move folder/files
    – Sunil Sahu
    Commented Sep 19, 2018 at 12:48

1 Answer 1

0

We can use SP.MoveCopyUtil.moveFolder method to move the specified folder to the destination.

Example code:

<script type="text/javascript">
function moveFolder(){
    ExecuteOrDelayUntilScriptLoaded(function(){
        var context = SP.ClientContext.get_current();
        SP.MoveCopyUtil.moveFolder(context,"https://mytestsite.sharepoint.com/Shared%20Documents/Folder1/Folder2/Active/02_NamedFolder","https://mytestsite.sharepoint.com/Shared%20Documents/Folder1/Folder2/Inactive/02_NamedFolder");
        context.executeQueryAsync(function(){
            alert("success.");
        },function(sender, args){
             alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace()); 
        });
    }, "sp.js");
}
</script>
<input type='button' onclick="moveFolder()" value="Move Folder"/>

Reference: How to use SP.MoveCopyUtil to copy (or move) files (or folders)

6

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.