Jul 10

Silverlight: Dowloading several images packaged on a ZIP file

Posted in Silverlight      Comments Off on Silverlight: Dowloading several images packaged on a ZIP file

One of the things you can in your Silverlight apps is package several items on a zip file and then download them through the Downloader object. Packaging several files and compressing them might increase your app”s performance, so this is something you should do whenever you can. Let”s run through a custom example. Let”s suppose we”ve got 2 pics called car.jpg and car2.jpg which are packaged on a zip file called You can start by downloading the zip file by running the following code:

Downloader d = new Downloader();
d.Open(“GET”, new Uri(“”, UriKind.Relative), true);
d.Completed += new EventHandler(d_Completed);

Now, let”s also suppose that our xaml page has an image (called img) and you want it to show the car2.jpg photo. No problem: that”s why you have the SetSource method! This method receives a downloader and a string, which lets you set the part name. The part name is used when you download a zip package and is just the name of the file from within the package you”ve just downloaded:

void d_Completed(object sender, EventArgs e)
    img.SetSource((Downloader)sender, “car2.jpg”);

Yes, that is really all you have to do!