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

  • 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 Sep 19 '18 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. – Amardeep Gupta Sep 19 '18 at 12:17
  • Ah yeah i see. To be honest I don't think you can move folders including content though. – Morten K Sep 19 '18 at 12:18
  • Manually we can do that, So there should exist some API to do the same. – Amardeep Gupta Sep 19 '18 at 12:45
  • are you ok with jsom to move folder/files – Sunil Sahu Sep 19 '18 at 12:48
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)

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.