Saving an image from the web to the Saved Pictures folder in Windows Phone 8.1 RT C#

ArthurRump

New member
Apr 22, 2014
19
0
0
Visit site
How can I save an image to the Saved Pictures folder in Windows Phone 8.1 RT? I downloaded the image from the web using HttpClient.
 

ArthurRump

New member
Apr 22, 2014
19
0
0
Visit site
I solved it thanks to mSpot Inc on the MSDN-forums. The code I use now:
Code:
StorageFolder picsFolder = KnownFolders.SavedPictures;
StorageFile file = await picsFolder.CreateFileAsync("myImage.jpg", CreationCollisionOption.GenerateUniqueName);

string url = "http://somewebsite.com/someimage.jpg";
HttpClient client = new HttpClient();

byte[] responseBytes = await client.GetByteArrayAsync(url);

var stream = await file.OpenAsync(FileAccessMode.ReadWrite);

using (var outputStream = stream.GetOutputStreamAt(0))
{
    DataWriter writer = new DataWriter(outputStream);
    writer.WriteBytes(responseBytes);
    writer.StoreAsync();
    outputStream.FlushAsync();
}
 

Members online

Forum statistics

Threads
324,057
Messages
2,244,904
Members
428,160
Latest member
smellincoffee