Brian Kessler
Brian Kessler

Reputation: 2327

In C# with CSOM, How can I copy a file from a known location to a known Folder?

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.

Give:

  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);
            context.ExecuteQuery();
            return itemFolder;

Upvotes: 0

Views: 1800

Answers (1)

Baker_Kong
Baker_Kong

Reputation: 1889

You can use CSOM File.CopyTo method or File.CopyToUsingPath method to copy a file to another location.

It's easy to get the file instance via the file location info.

BR

Upvotes: 1

Related Questions