Willcode4cash

Download Image via URI (.NET Core)

Jun 22nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. public static async void GetImage(Uri uri, string filePath)
  2. {
  3.     using(var client = new HttpClient())
  4.     {
  5.         using(var request = new HttpRequestMessage(HttpMethod.Get, uri))
  6.         {
  7.             using(Stream contentStream = await (
  8.                 await client.SendAsync(request)).Content.ReadAsStreamAsync(),
  9.                 stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, 3145728, true))
  10.             {
  11.                 await contentStream.CopyToAsync(stream);
  12.             }
  13.         }
  14.     }
  15. }
Add Comment
Please, Sign In to add comment