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"];


    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;
        destLibrary.Context.ExecuteQueryWithIncrementalRetry(3, logger);

Is there anyway to to the same in batches? Notice SaveBinary etc cannot be used with modern authentication.


1 Answer 1


This one solves the problem:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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