I have one function which uses SearchExecutor finds to find the path of a specified file, which returns a string like.

https://example.sharepoint.com/sites/DevelopementTestingSite/Shared Documents/Forms/DispForm.aspx?ID=43

I have another function which creates and returns a Microsoft.SharePoint.Client.Folder.


  1. The filename,
  2. The file location, and
  3. The Folder.

How can I copy the file to the folder?

If it helps, the ServerRelativePath has been initialized on the Folder with:

            Folder itemFolder = folderItem.Folder;
            context.Load(itemFolder, folder => folder.ServerRelativePath);
            return itemFolder;

1 Answer 1


In the string https://example.sharepoint.com/sites/DevelopementTestingSite/Shared Documents/Forms/DispForm.aspx?ID=43, you could get the file by the id. Then copy to the folder.

My test demo code :

        Web web = ctx.Web;
        List list = web.GetListByTitle("Documents");
       // ctx.Load(list);
        ListItem item = list.GetItemById(2);
        File file = item.File;
        item.File.CopyTo("/sites/test/Shared%20Documents/folder1/"+item.File.Name, true);
  • cheers for the info. I'm trying to play with it currently. Do I correctly understand that I can disregard most of the file location other than the id, as long as I access the "Documents" List? Nov 24, 2020 at 10:52
  • 1
    Yes. You only need to use the listname and the id, that will be enough. Nov 25, 2020 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.