C# CSOM Sharepoint Timeout when downloading a lot of files

Veröffentlicht von

I ran into a timeout exception, when using OpenFileBinaryDirect, to download files from Sharepoint.

The solution was to put the fileinfo object into a using statement.

using (var fileInfo = File.OpenBinaryDirect(_context, relativeUrl))
{
    if (Directory.Exists(targetDirectory))
    {
        targetDirectory = Path.Combine(targetDirectory,
            Path.GetFileName(new Uri(relativeUrl).LocalPath));
    }
 
    using (Stream destination = System.IO.File.Create(targetDirectory))
    {
        for (var a = fileInfo.Stream.ReadByte(); a != -1; a = fileInfo.Stream.ReadByte())
            destination.WriteByte((byte)a);
    }
}

It seems that without proper disposing the object, you run into some sort of connection limit. It put the code also on Stackoverflow.

Kommentar hinterlassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert