Windows Phone 7 download image and display it
c#, filestream, windows-phone-7
Solution
A picture is binary content, not a string. You have either to use `WebClient.OpenReadAsync` (instead of `DownloadStringAsync`), or set directly your url as source for your `BitmapImage`:
var bi = new BitmapImage(new Uri("http://some-url-image-name.jpg"));
Problem
I'm a newbie to windows phone platform, and I'm trying to build a simple application that reads an image url from textbox, and upon a download button click downloads this image to the phone memory and then displays it in an Image control. this code is written when the user clicks on the download button: ``` string url = "http://some-url-image-name.jpg"; WebClient client = new WebClient(); client.DownloadStringCompleted += DownloadCompleted; client.DownloadStringAsync(new Uri(url)); ``` and this is the DownloadStringCompleted event handler: ``` private void DownloadCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) return; string result = e.Result; using (var stream = new MemoryStream(Encoding.Unicode.GetBytes(e.Result))) { var bi = new BitmapImage(); bi.SetSource(stream); image.Source = bi; } } ``` it is giving an 'unspecified error' exception. How to solve it? or does anybody know a better approach to do this ? Another question, what is the nature of e.Result? is it the downloaded image content as a string or the path to something or what ? Thanks