Skip to content

Instantly share code, notes, and snippets.

@Mogikan
Created March 24, 2020 12:51
Show Gist options
  • Save Mogikan/03fe4a4cf53f9473657d25c367a90d1d to your computer and use it in GitHub Desktop.
Save Mogikan/03fe4a4cf53f9473657d25c367a90d1d to your computer and use it in GitHub Desktop.
public MainPage()
{
this.InitializeComponent();
Loaded += MainPage_Loaded;
}
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
string url = "https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg";
var file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("photo.jpg");
HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get, url);
var client = new HttpClient();
HttpResponseMessage response = await client.SendAsync(req);
using (Stream responseStream = await response.Content.ReadAsStreamAsync())
{
var fileStream = new FileStream(file.Path, FileMode.Open);
await responseStream.CopyToAsync(fileStream);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment