Hi, I am using OpenBinaryDirect to download file from SharePoint online.
When I am using fileInfo.Stream.CopyTo(filestream), code is able to download file.
var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, fileRef);
//Below is the working code.
using (FileStream filestream = new FileStream("C:" + "\\" + file.Name, FileMode.Create))
{
fileInfo.Stream.CopyTo(filestream);
}
But when I am using below code, for some files it is not downloading complete file. The file which is giving me error is of size 4Mb but below code only download 1.5MB and because of that I am getting file corrupted error.
//Code which is not downloading complete file
byte[] buffer = new byte[1024 * 100];
int len;
while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, len);
}