0

I wanted to save the unzipped file to a folder in IsolatedStorage. I have read the file zip file from IsolatedStorage and now want to unzip them into a folder. i have tried this way :-

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.
            } 
    }
loop
  • 9,002
  • 10
  • 40
  • 76
  • You're going to want to get the file's stream from the unzipper (no idea, check their docs) [then copy that stream to the filestream](http://stackoverflow.com/a/230141/1228). –  Jun 27 '14 at 15:56
  • You opened a file stream (look at the variable `fileStream`) in iso storage, your comment shows how to get the stream of the compressed file from the zip file, now just copy the contents of the zip stream to `fileStream`. It's like one line, `zipStream.CopyTo(fileStream)` –  Jun 27 '14 at 16:03
  • 1
    You aren't creating a folder in iso storage [Here's how](http://msdn.microsoft.com/en-us/library/6h2ws3ft(v=vs.110).aspx). Not sure where you are having the problem. –  Jun 27 '14 at 17:02

1 Answers1

1

Here is what i got :) Hope it will help somebody.

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));
                }
            }
        }
    }
}
loop
  • 9,002
  • 10
  • 40
  • 76