Wednesday, August 26, 2015

SP2016 - O365 - SP.MoveCopyUtil - Javascript Copy - Move Files and Folder

SharePoint 2016 (Preview) has the Copy / Move files or folders api using CSOM and JSOM. 

The SP.js contains the following api's,

  • SP.MoveCopyUtil.copyFile
  • SP.MoveCopyUtil.copyFolder
  • SP.MoveCopyUtil.moveFile
  • SP.MoveCopyUtil.moveFolder

Each of the method takes 3 parameters,

  • context - current context
  • source url - Full source url of the file / folder.
  • destination url - Full destination url of the file / folder.

SP.MoveCopyUtil.copyFile: This copies the specified file to the destination url.

var context = SP.ClientContext.get_current();
SP.MoveCopyUtil.copyFile(context,"http://sp2016/sitepages/home.aspx","http://sp2016/sitepages/home1.aspx"); context.executeQueryAsync(function(){},function(){});

The above code copies the /sitepages/home.aspx file to sitepages/home1.aspx with all the metadata including createdtime, author etc.

SP.MoveCopyUtil.copyFolder: Copies the specified folder to the destination url including the files within it.

var context = SP.ClientContext.get_current();
SP.MoveCopyUtil.copyFolder(context,"http://sp2016/sitepages/homeFolder","http://sp2016/sitepages/HomeFolder1") context.executeQueryAsync(function(){},function(){});

SP.MoveCopyUtil.moveFolder: Moves the specified folder to the destination.

var context = SP.ClientContext.get_current();
SP.MoveCopyUtil.moveFolder(context,"http://sp2016/sitepages/homeFolder","http://sp2016/pages/HomeFolder1"); context.executeQueryAsync(function(){},function(){});

SP.MoveCopyUtil.moveFile: Moves the specified file to the destination url.

var context = SP.ClientContext.get_current();
SP.MoveCopyUtil.moveFile(context,"http://sp2016/sitepages/home1.aspx","http://sp2016/pages/home1.aspx"); context.executeQueryAsync(function(){},function(){});

The equivalent CSOM api is also available within the Microsoft.SharePoint.Client.MoveCopyUtil. The above api's are also available within O365.


by Balamurugan Kailasam via Everyone's Blog Posts - SharePoint Community

1 comment:

  1. HI,

    I am getting size limit error when trying to move file >= 100 mb in office365

    ReplyDelete