我想将解压缩的文件保存到IsolatedStorage中的文件夹中。我已经从IsolatedStorage读取了文件zip文件,现在想将它们解压缩到一个文件夹中。我试过这种方式: -
private async Task UnZipFile(string fileName)
{
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(fileName, FileMode.Open, FileAccess.ReadWrite))
{
UnZipper unzip = new UnZipper(fileStream);
var filename = unzip.FileNamesInZip.FirstOrDefault();
if (filename != null)
{
// i can have the stream too. like this.
// var zipStream = unzip.GetFileStream(filename)
// here i am not getting how to save unzip file to a folder.
}
}
答案 0 :(得分:1)
这是我得到的:)希望它会帮助某人。
private async Task UnZipFile()
{
// you can use Isolated storage too
var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
using (var fileStream = Application.GetResourceStream(new Uri("sample.zip", UriKind.Relative)).Stream)
{
var unzip = new UnZipper(fileStream);
foreach (string filename in unzip.FileNamesInZip)
{
if (!string.IsNullOrEmpty(filename))
{
if (filename.Any(m => m.Equals('/')))
{
myIsolatedStorage.CreateDirectory(filename.Substring(0, filename.LastIndexOfAny(new char[] { '/' })));
}
//save file entry to storage
using (var streamWriter =
new StreamWriter(new IsolatedStorageFileStream(filename,
FileMode.Create,
FileAccess.ReadWrite,
myIsolatedStorage)))
{
streamWriter.Write(unzip.GetFileStream(filename));
}
}
}
}
}