LA.NET [EN]

Jul 10

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 test.zip. You can start by downloading the zip file by running the following code:

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

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!

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>