问题
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