0

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.

2
  • Did you try recommendations in docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/…? Commented Oct 13, 2019 at 4:34
  • Thanks. Yes I read that article, but it is based on uploading a file from disk. I havent found a sample where you can do OpenBinaryStream in batches. Options 3 would be the prefered one but from memory only. Commented Oct 13, 2019 at 8:48

1 Answer 1

0

This one solves the problem:

https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-csom/mt796381(v%3Doffice.15)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.