Windows Phone 7 中如何提取 Zip 中的文件

.Net技术 针尖舞 8年前 (2016-01-29) 2240次浏览 0个评论

在我的 Windows Phone 7 项目中有一个 zip 文件。我已经设置生成操作为内容和复制到输出目录为始终。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); 

然而当调用 ExractZip 时遇到错误。我得到的异常是”MethodAccessException”。不能调用 GetFullPath()。希望有人可以让我知道我错过了什么?我怎样才能避免它?
签出此实用程序,它会帮助你理解。

http://www.sharpgis.net/post/2009/04/22/REALLY-small-unzip-utility-for-Silverlight.aspx

回答1:

如果你知道你想要的 Zip 文件。你就不需要使用另一个库,你可以使用 App.GetResourceStream phone 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;
}

想要获取更多的信息,可以读取Zip 的文件列表,参考 博客文章.

我使用 SharpZipLib 的 SL 端口做过,请参阅 http://slsharpziplib.codeplex.com/

有很多关于如何使用的代码示例,源代码中也会有快速入门指导。 – http://slsharpziplib.codeplex.com/SourceControl/changeset/view/75568#1416103


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Windows Phone 7 中如何提取 Zip 中的文件
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!