I am trying move files from one site collection to another. Following code works for smaller files but not for large files due to memory exceptions:
if (item.FileSystemObjectType == FileSystemObjectType.File)
{
var fileName = item["FileLeafRef"] as string;
var fileSize = item["File_x0020_Size"];
item.Context.Load(item.File);
using (var stream = item.File.OpenBinaryStream().Value)
{
item.Context.ExecuteQueryWithIncrementalRetry(3, logger);
var fi = new FileCreationInformation();
fi.ContentStream = stream;
fi.Url = fileName;
fi.Overwrite = true;
folder.Files.Add(fi);
destLibrary.Context.ExecuteQueryWithIncrementalRetry(3, logger);
}
}
Is there anyway to to the same in batches? Notice SaveBinary etc cannot be used with modern authentication.