如何在Windows Phone 7中提取zip文件?

TCM*_*TCM 3 silverlight sharpziplib windows-phone-7

我的Windows Phone 7项目中有一个zip文件.我已将Build Action to Content和Copy to output目录设置为Always.zip文件包含文件夹结构.我希望这完全复制,因为它在我的电话项目中.我正在使用SharpZipLib.这是代码: -

 Stream stremInfo = Application.GetResourceStream(new Uri("xip.zip", UriKind.Relative)).Stream;



        new FastZip(). ExtractZip(stremInfo,
            "",FastZip.Overwrite.Always,null,null,null,true,true);
Run Code Online (Sandbox Code Playgroud)

但是,在调用ExractZip时出现错误.我得到的例外是" MethodAccessException".不能打电话GetFullPath().任何人都可以让我知道我错过了什么?我该怎么做才能避免它?

Chr*_*son 7

如果您知道Zip中需要哪些文件,则无需使用其他库.您可以使用App.GetResourceStream手机API访问Zip并获取文件.

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;
}
Run Code Online (Sandbox Code Playgroud)

有关阅读Zip文件列表的更多信息,请查看此博客文章.