How do I extract zip file in Windows Phone 7?

允我心安 提交于 2019-12-05 23:05:32

You dont need to use another library if you know what files you want out of the Zip. You can use the App.GetResourceStream phone API to reach into the Zip and get the file.

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    WebClient client = new WebClient();
    client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
    client.OpenReadAsync(new Uri("http://www.foo.com/pictures.zip"));
}

void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    StreamResourceInfo info = new StreamResourceInfo(e.Result,"");
    StreamResourceInfo pic = App.GetResourceStream(info, new Uri("IMG_1001.jpg", UriKind.Relative));

    BitmapImage bitmap = new BitmapImage();
    bitmap.SetSource(pic.Stream);
    img.Source = bitmap;
}

For more informaiton on reading the list of files from th Zip check out this blog post.

I've used the SL port of the SharpZipLib to do this - see http://slsharpziplib.codeplex.com/

There's lots of example code available for how to use it - and a good quickstart in their source - http://slsharpziplib.codeplex.com/SourceControl/changeset/view/75568#1416103

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!