I’m don’t really understand why compress or zip function was not added to Silverlight or Windows Phone since the Silverlight package or Windows Phones xap file was actually a zip file. Windows Phone will need to unzip all file download from marketplace in order to install in the phone. While I’m looking for a third party library to unzip file in my Windows Phone app, I come across this REALLY small unzip utility for Silverlight, which re-use the existing functions in Silverlight to done the job. Great, this is just what I looking for and the best part of it, the size is really small. It is just a C Sharp file!
A very simple tutorial for REALLY small unzip utility for Silverlight was provided on his blog but I found a missing function in the code. The GetFileNamesInZip can’t be found by Visual Studio. After taking a quick look in the source file, I found out that the function name was changed to FileNamesInZip instead. Below are the same example but with corrected function name call instead.
private void LoadZipfile()
{
WebClient c = new WebClient();
c.OpenReadCompleted += new OpenReadCompletedEventHandler(openReadCompleted);
c.OpenReadAsync(new Uri("http://www.mydomain.com/myZipFile.zip"));
}
private void openReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
UnZipper unzip = new UnZipper(e.Result);
foreach (string filename in unzip.FileNamesInZip())
{
Stream stream = unzip.GetFileStream(filename);
StreamReader reader = new StreamReader(stream);
string contents = reader.ReadToEnd();
MessageBox.Show(contents);
}
}
Download REALLY small unzip utility for Silverlight
by Ooi Keng Siang via Ooiks’s Blog