3

I am using listbox where I am populating the listbox with the images with the absolute uri. Now i need to save the images to my media library within my phone. But when I try:

Application.GetResourceStream(new Uri(imageurl, UriKind.absolute))

it fires an exception. Is there any way to solve this problem.

Thanks in advance.

master.fake
  • 487
  • 1
  • 6
  • 22

2 Answers2

9

Here's what I found as solution and it worked:

        WebClient client = new WebClient();
        client.OpenReadCompleted += (s, e) =>
            {
                if (e.Error == null)
                {
                    MediaLibrary library = new MediaLibrary();
                    library.SavePicture(imageName, e.Result);
                }
            };
        client.OpenReadAsync(new Uri(imageAbsoluteUrl, UriKind.Absolute));
master.fake
  • 487
  • 1
  • 6
  • 22
0

If you're referencing imageswith an absolute Uri then they won't be part of the application and so therefore not accessible as a resource stream.

You'll need to download the image to get the stream directly and then write it to the media library.

Matt Lacey
  • 65,560
  • 11
  • 91
  • 143