Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 7025

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 2162

Deprecated: Hook imagify_allow_picture_tags_for_webp is deprecated since version 2.2! Use imagify_allow_picture_tags_for_nextgen instead. in /www/collab365_296/public/wp-includes/functions.php on line 5758
How to use SP.MoveCopyUtil to copy (or move) files (or folders) - Collab365
Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Warning: Undefined array key "url" in /www/collab365_296/public/wp-content/plugins/thrive-visual-editor/thrive-dashboard/inc/smart-site/classes/class-tvd-smart-shortcodes.php on line 85

2015-08-26

SharePoint 2016 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.

How to copy a file in SharePoint using Javascript

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.

How to copy a folder in SharePoint using Javascript

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(){});

How to move a folder in SharePoint using Javascript

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(){});

How to move a file in SharePoint using Javascript

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.

(Visited 2,910 times, 1 visits today)

About the author 

Balamurugan Kailasam

Summit Bundle

Get 200+ hours of Microsoft 365 Training for 27$!

Master Office 365, Power Platform & SharePoint & Teams With 200+ Hours Of Training Videos and 108 Ebooks in the Collab365 Academy. This offer is insane and is only available for a limited period.