I have to all files from one folder another folder using CSOM and C# Thanks for your replay Huge Wood
my code is below
var targetSite = new Uri("https://hello.com//teams/Worldwide_Site");
string src = @"/teams/Worldwide_Site/Shared Documents/BI/Reports/march";
string dest = @"/teams/Worldwide_Site/Shared Documents/BI/Reports/April";
string lst = "Reports";
MoveFiles(targetSite, lst, src, dest);
public static void MoveFiles(Uri url, string listTitle, string srcFolder,string destFolder)
{
using (var context = new ClientContext(url))
{
var login = "hello.com";
var password = "xyz";
var securePassword = new SecureString();
foreach (char c in password)
{
securePassword.AppendChar(c);
}
context.Credentials = new SharePointOnlineCredentials(login, securePassword);
var srcList = context.Web.Lists.GetByTitle(listTitle);
var qry = CamlQuery.CreateAllItemsQuery();
qry.FolderServerRelativeUrl = srcFolder;
var srcItems = srcList.GetItems(qry);
context.Load(srcItems, icol => icol.Include
(i => i.FileSystemObjectType,
i => i.File));
context.ExecuteQuery();
foreach (var item in srcItems)
{
if (item.FileSystemObjectType == FileSystemObjectType.File)
{
var destFileUrl = string.Format("{0}/{1}/{2}", listTitle, destFolder, item.File.Name);
item.File.MoveTo(destFileUrl, MoveOperations.Overwrite);
context.ExecuteQuery();
}
}
}
}
I'm getting the issue in context.ExecuteQuery error like Folder "April" is not found as per my understood destination path is not correct but where I did wrong?