Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I download images (jpg) via a webclient and save to isolated storage on Windows Phone 7?
    text
    copied!<p>Due to my lack of programming experience (3 months) I have been unable to recreate any found examples of the above question. The examples I have found relate to non WP7 Silverlight, camera based saving of images, have been to complex for my needs or have just not worked. I have been able to download a text file using an instance of the Webclient and save it to isolated storage using StreamWriter. I need to acomplish the same task with jpg images. Below is what I have used to download the text file.</p> <p>===============================================================================</p> <pre><code> IsolatedStorageFile MyStore = IsolatedStorageFile.GetUserStoreForApplication(); private void GetTextFile() { WebClient client = new WebClient(); client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted); client.DownloadStringAsync(new Uri("http://mywebsite.com/textfile.txt")); } private void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { StreamWriter MyStreamWriter = new StreamWriter(new IsolatedStorageFileStream("textfile.txt", FileMode.Create, MyStore)); MyStreamWriter.WriteLine(e.result) MyStreamWriter.Close(); } </code></pre> <p>===============================================================================</p> <p>I have removed a few lines used to handle errors etc to keep it as simple as posible.</p> <p>Please could someone modify the above to enable me to download and save a jpg?</p> <p>Please keep it as simple as possible as I am easily confused.</p> <p>Thank you for your time in advance!</p> <p>RESOLVED!===============================================================================</p> <p>I managed to get it working using information from this site below. <a href="http://dotnet.dzone.com/articles/operating-image-files-windows" rel="noreferrer">http://dotnet.dzone.com/articles/operating-image-files-windows</a> </p> <p>Hopefully this will help other frustrated newbie's in the future!</p> <pre><code>IsolatedStorageFile MyStore = IsolatedStorageFile.GetUserStoreForApplication(); private void GetImageFile() { WebClient client = new WebClient(); client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted); client.OpenReadAsync(new Uri("http://mywebsite.com/1.jpg"), client); } void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { var resInfo = new StreamResourceInfo(e.Result, null); var reader = new StreamReader(resInfo.Stream); byte[] contents; using (BinaryReader bReader = new BinaryReader(reader.BaseStream)) { contents = bReader.ReadBytes((int)reader.BaseStream.Length); } IsolatedStorageFileStream stream = MyStore.CreateFile("10.jpg"); stream.Write(contents, 0, contents.Length); stream.Close(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload