我被困在这个问题 - 显然,我做错了什么。从隔离存储提取zip文件
首先,我通过Web客户端下载一个压缩文件,并将其存储到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());
}
}
接着,我中提取一个特定的文件从Web客户端响应(zip文件)的:
Uri fileUri = new Uri("content.txt", UriKind.Relative);
StreamResourceInfo info = new StreamResourceInfo(e.Result, null);
StreamResourceInfo streamInfo = System.Windows.Application.GetResourceStream(info, fileUri);
这按预期工作。后来,我想这个提取从IsolatedStorage zip文件中的“content.txt”:
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);
}
}
虽然zip压缩包,可以发现,streamInfo始终为空。我究竟做错了什么?
哪个zip文件?如果你确实想从'IsolatedStoage'中读取,你为什么要用'StreamResourceInfo'而不是'StreamReader'! – Anirudha 2012-07-31 14:42:06
@Airirha zip文件位于isolatedstorage文件夹中:AppData \\“+ FileName 我正在使用StreamResourceInfo,因为它可以本地访问压缩的zip压缩文件 – Jasper 2012-08-01 07:28:07