I would suggest trying the WebClient class using the DownloadData or DownloadDataAsync method.
File.WriteAllBytes("myfile.png", new WebClient().DownloadData("<your url>"));
edit If the stream creates problems, you can use the response of the byte array. Your using statement with asynchronous code inside may call it earlier, maybe?
var httpClient = new HttpClient(); var data = await httpClient.GetByteArrayAsync(new Uri("<Your URI>")); var file = await KnownFolders.PictureLibrary.CreateFileAsync("myfile.png"); var targetStream = await file.OpenAsync(FileAccessMode.ReadWrite) await targetStream.AsStreamForWrite().WriteAsync(data, 0, data.Length); targetStream.FlushAsync().Wait(); targetStream.Close();
Louis ricci
source share