Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
Added the possibility to download a file using an HttpClient (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Mar 6, 2022
1 parent 9afcd7d commit 22a2180
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions LeoCorpLibrary/NetworkConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ MIT License
*/
using LeoCorpLibrary.Enums;
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;

Expand Down Expand Up @@ -225,5 +226,16 @@ public static StatusCodeType GetStatusCodeType(string url)
return StatusCodeType.ClientError; // Return ClientError
}
}

public static async Task DownloadFileAsync(Uri uri, string filePath)
{
using (var s = await new System.Net.Http.HttpClient().GetStreamAsync(uri))
{
using (var fs = new FileStream(filePath, FileMode.CreateNew))
{
await s.CopyToAsync(fs);
}
}
}
}
}

0 comments on commit 22a2180

Please sign in to comment.