The process of building custom applications and tools that interact with Microsoft SharePoint, including SharePoint Online in Microsoft 365.
Per my test, the MoveCopyUtil works for me. Below is my demo code:
var userName = "******@tenant.onmicrosoft.com";
var password = "xxxx";
var siteUrl = "https://tenant.sharepoint.com/sites/test";
SecureString securePassword=new SecureString();
foreach(char a in password)
{
securePassword.AppendChar(a);
}
var credential = new SharePointOnlineCredentials(userName, securePassword);
var ctx = new ClientContext(siteUrl);
ctx.Credentials = credential;
var srcUrl="https://tenant.sharepoint.com/sites/test/Shared%20Documents/aa.txt";
var desUrl="https://tenant.sharepoint.com/sites/test/sub1/Shared%20Documents/aa.txt";
MoveCopyOptions lOptions = new MoveCopyOptions();
lOptions.ResetAuthorAndCreatedOnCopy = false;
MoveCopyUtil.CopyFile(ctx, srcUrl, desUrl,true, lOptions);
ctx.ExecuteQuery();
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.