I have a library like below :

---------Folder 1
---------File 0
---------File 1
-----------------Folder 2
------------------------File 2
------------------------File 3
---------Folder 3
-----------------File 4
-----------------File 5

The plan is to copy it to another library, i have found a way to copy the File 0 / File 1. But i'm looking for a way to copy all the library (folder with subfolder and file inside) to my other library.

To copy the file i did this:

SPListItem item = oldLib.GetItemById(collItem[i].ID);
byte[] fileBytes = item.File.OpenBinary();
string destUrl = newlib.RootFolder.Url + "/" + item.File.Name;
SPFile destFile = newlib.RootFolder.Files.Add(destUrl, fileBytes, true);

Did i miss an easy way to do what i want?

Best regards

2 Answers 2


You can use SPFile CopyTo / MoveTo methods.

file.CopyTo(destUrl, true);


You can use SP.MoveCopyUtil.moveFolder() method to Move Folder From one Document Library to another Document Library. Instead of Coping file from one document library to another.
Try to use Following code, It's work for me :-

function moveFolder() {
  ExecuteOrDelayUntilScriptLoaded(function () {
  var context = SP.ClientContext.get_current();

   context.executeQueryAsync(function () {
    }, function (sender, args) {
           alert('request failed ' + args.get_message() + '\n' 
}, "sp.js");

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.