Copy or Move Folder Structure in SharePoint Using CSOM

This post is intended for SharePoint Online and 2016+ using CSOM.

In previous version of SharePoint, moving a folder structure to a different library or a different library in another site collection required a good amount of code and effort. With the introduction of Microsoft.SharePoint.Client.MoveCopyUtil we now have the ability to use methods like MoveFolder to perform a cut and paste of a folder structure. There are other methods that are worth exploring like FolderCopy that is a copy and paste of a structure.

More methods can be found here: MoveCopyUtil members

Name Description
Public method Static member CopyFile
Public method Static member CopyFileByPath
Public method Static member CopyFolder
Public method Static member CopyFolderByPath
Public method Static member MoveFile
Public method Static member MoveFileByPath
Public method Static member MoveFolder
Public method Static member MoveFolderByPath

Example of moving a folder between site collections.

string dstUrl = "";

using (ClientContext srcContext = new ClientContext(dstUrl))
  string sourceFolder = "";
  string destFolder = dstUrl + "libraryname/foldername";

  MoveCopyUtil.MoveFolder(srcContext, sourceFolder, destFolder);

Again, this is using CSOM with the latest version of the NuGet package (16.0.4351.1000).

11 thoughts on “Copy or Move Folder Structure in SharePoint Using CSOM

  1. Hi, I was googling copying folder structure to SharePoint and I found this page. However, in my particular case, I want to copy a folder structure form a shared folder location in my local network.
    Can you please tell me if there is a similar procedure that uses the shared folder path \\server\shareFolder\folderStructure to copy the folder structure to a SharePoint library?

  2. This post on stackexchange will get you headed in the right direction. Link:

    It’s a little more involved than simply copying folders around SP but it’s fairly straightforward. Also, be sure to check out what SharePoint PNP has to offer for copying files from your serer to SP.


  3. hi i want to ask about if we found duplicate name file or folder it’s posible to replace new version? so replace to version 2.

  4. hi ian it’s on power shell?how to do like that on CSOM?when i try to

    MoveCopyOptions option = new MoveCopyOptions();
    option.KeepBoth = true;
    MoveCopyUtil.CopyFile(this.clientContext, SrcUrl, DestUrl, true, option);

    overwrite is true but still not and getting error destination exists work to overwrite my Src is




  5. Did you try this: MoveCopyUtil.MoveFolder(srcContext, sourceFolder, destFolder, true);

    I’m not at my work PC but I will try it tomorrow.

  6. I was trying moving multiple folders and files. I am getting error File Size Limitation. What should I do ?

Leave a Reply

Your email address will not be published. Required fields are marked *