none
Moving Folders with REST API using javascript RRS feed

  • Question

  • The latest online version of Sharepoint contains the ability to move a folder to a new location within the same Document Library.

    I was wondering if there is a command within the REST API that allows this to be done.  I have not been able to find any recent information on the internet relating to "folder, move, moveto" keywords.

    If it is not currently available, will it be available at some point? and if so, roughly where would I find information about this?

    Thanks in advance

    Greg J

    Wednesday, April 26, 2017 4:03 AM

Answers

  • I have found the answer.  Unfortunately for some this solution is only available in Sharepoint 2016.  Seeing as I am looking for the solution for Sharepoint Online this is the answer for me.

    There are new commands available to copy/move files/folders under SP.MoveCopyUtil.

    This makes moving and copying so much more simpler than current solutions.

    To perform the "move folder" task within the same document library, use this...

    var currfdr = 'https://mydomain.sharepoint.com/doc-lib/path-to-folder';
    var newfdr = 'https://mydomain.sharepoint.com/doc-lib/path-to-new-folder';
    
    var context = new SP.ClientContext.get_current();
    SP.MoveCopyUtil.moveFolder(context, currfdr, newfdr);
    context.executeQueryAsync(copyMoveSuccess, copyMoveError);
    


    Friday, May 5, 2017 6:37 PM

All replies

  • Hi,

    So, you want to copy folder in SharePoint 2013?

    For OOTB solution, you could use ‘Open with Explorer’ for that.

    https://support.office.com/en-us/article/Move-or-copy-a-folder-file-or-link-in-a-document-library-00e2f483-4df3-46be-a861-1f5f0c1a87bc?ui=en-US&rs=en-US&ad=US#ID0EAADAAA=2013

    If you want to do this programmatically, you could retrieve list items of folder and then move by CSOM or SSOM, here is one thread for your reference.

    http://mohan1315.blogspot.sg/2013/11/move-folders-of-sharepoint-document.html

     

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, April 27, 2017 2:59 AM
  • Hi,

    so i am thing that you are looking out for option which is now available in document library to move file to other other folder or folder to other folder refer link  so you find MoveTo method


    Abhijeet S. Thorat



    If my post solves your problem could you mark the post as Answered or Vote As Helpful if my post has been helpful for you.

    Thursday, April 27, 2017 7:24 AM
  • not looking for OOTB solution.  Already know how to do that with Explorer.  Question specifically refers to performing the action with REST API and JAVASCRIPT

    Moving a folder "should" be as simple as changing a folders parent to another folder.  But that would depend on how the folder/file data is structured in the first place.

    A solution that requires a folder structure to be replicated, copied then deleted sounds horribly over-complicated but may be necessary if the data structure dictates it. 

    Can anyone confirm how the file/folder data is structured for Document Libraries?

    Its possible that a folder to be moved could contain thousands of folders and tens of thousands of files so doing the process "the long way" would probably cause me more problems than not offering the option at all.

    Cheers

    Greg J

    Tuesday, May 2, 2017 5:21 AM
  • The "moveto" action on this page (which I have already seen and used quite a number of times for moving files and other actions outlined in the page) refers to moving a FILE,  the question specifically states MOVE FOLDER
    Tuesday, May 2, 2017 5:23 AM
  • Hi,

    There is no REST API to move folder currently as per my knowledge, you have to retrieve the folders and create and then move the files.

    As you’re restricted for JavaScript solution, you could create folder by JavaScript as below:

    executor.executeAsync({
      url: "<app web url>/_api/SP.AppContextSite(@target)/web/folders
        /add('/Shared Documents/Folder A/Folder B')
        ?@target='<host web url>'",
      method: "POST",
      headers: { "accept": "application/json; odata=verbose" },
      success: successHandler,
      error: errorHandler
    });


    You could check below link for details.

    https://msdn.microsoft.com/en-us/library/office/dn450841%28v=office.15%29.aspx?f=255&MSPPError=-2147217396#bk_FolderMethods

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, May 2, 2017 7:04 AM
  • I have found the answer.  Unfortunately for some this solution is only available in Sharepoint 2016.  Seeing as I am looking for the solution for Sharepoint Online this is the answer for me.

    There are new commands available to copy/move files/folders under SP.MoveCopyUtil.

    This makes moving and copying so much more simpler than current solutions.

    To perform the "move folder" task within the same document library, use this...

    var currfdr = 'https://mydomain.sharepoint.com/doc-lib/path-to-folder';
    var newfdr = 'https://mydomain.sharepoint.com/doc-lib/path-to-new-folder';
    
    var context = new SP.ClientContext.get_current();
    SP.MoveCopyUtil.moveFolder(context, currfdr, newfdr);
    context.executeQueryAsync(copyMoveSuccess, copyMoveError);
    


    Friday, May 5, 2017 6:37 PM