Extract zip file from isolatedstorage

烈酒焚心 提交于 2019-12-02 08:51:12

问题


I am stuck at this problem - obviously, I am doing something wrong.

First, I download a zip file via WebClient and storing it into IsolatedStorage:

using (var isf = IsolatedStorageFile.GetUserStoreForApplication()) 
{ 
    if (!isf.DirectoryExists("AppData")) isf.CreateDirectory("AppData"); 
    using (StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream("AppData\\" + FileName, FileMode.OpenOrCreate, isf))) 
    { 
        sw.Write(new StreamReader(e.Result).ReadToEnd()); 
    } 
}

Next, I extract one specific file out of the WebClient response (the zip file):

Uri fileUri = new Uri("content.txt", UriKind.Relative); 
StreamResourceInfo info = new StreamResourceInfo(e.Result, null); 
StreamResourceInfo streamInfo = System.Windows.Application.GetResourceStream(info, fileUri); 

This works as expected. Later on, I want to extract the "content.txt" from the zip file in IsolatedStorage with this:

using (IsolatedStorageFileStream isfs = isf.OpenFile("AppData\\" + FileName, FileMode.Open, FileAccess.Read)) 
{ 
    if (myIsolatedStorage.FileExists("AppData\\" + FileName)) 
    { 
        Uri fileUri = new Uri("content.txt", UriKind.Relative); 
        StreamResourceInfo info = new StreamResourceInfo(isfs, null); 
        StreamResourceInfo streamInfo = System.Windows.Application.GetResourceStream(info, fileUri); 
    } 
} 

Although the zip archive can be found, streamInfo is always null. What am I doing wrong?


回答1:


Unfortunately, unlike the desktop .Net framework, the Windows Phone 7.x framework does not know how to stream from a compressed file. In fact, on Windows Phone you don't have access to the System.IO.Compression namespace at all.

Fortunately, the DotNetZip library works fine for WP7 apps. You'll want to use the Compact Framework binary DLL, not the Silverlight one. Visual Studio will complain the library may not be compatible when adding the reference, but it'll work just fine.



来源:https://stackoverflow.com/questions/11742348/extract-zip-file-from-isolatedstorage

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