Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6746483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:19:42+00:00 2026-05-26T12:19:42+00:00

I have problems in using SharpZipLib with isolated storage in WP7 to zip subfolders

  • 0

I have problems in using SharpZipLib with isolated storage in WP7 to zip subfolders in isolated storage. My folder structure is like I’m having a rootFolder in isolated storage and inside that there is subFolder having some text files and more subfolders (contains .jpg and .png). I could go for Dotnetzip but I’m not sure it is available for WP7 or not and about its usage.

  1. I am able to get all the file pathes in a list by recursively traversing on root folder. At present I am able to zip multiple files but only when they are inside a single folder.

  2. Can’t find way to zip subFolder with correct hierarchy of folder and file structure and save it inside isolated storage. Also needs to unzip it with correct folder and file structure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:19:42+00:00Added an answer on May 26, 2026 at 12:19 pm

    You can do this with SharpZipLib for Silverlight/Windows Phone 7.

    The following code is based on this example and demonstrates how to zip a root folder including subfolders and files.

    Short overview:

    • button1_Click prepares some dummy folders and files for proof of concept: a folder root containing a file and two subfolders each also containing a file, then it calls CreateZip to compress the whole directory tree starting with root
    • CreateZip prepares the zip file and starts recursive folder compression by calling CompressFolder
    • CompressFolder adds all files in a given dir to the zip file and recurses into subdirectories

    The code:

        using System.IO.IsolatedStorage;
        using ICSharpCode.SharpZipLib.Zip;
        using ICSharpCode.SharpZipLib.Core;
        using System.Text;
    
        // Recurses down the folder structure
        //
        private void CompressFolder(string path, ZipOutputStream zipStream, int folderOffset, IsolatedStorageFile isf)
        {
    
            string[] files = isf.GetFileNames(System.IO.Path.Combine(path, "*.*"));
    
            foreach (string filename in files)
            {
                string filenameWithPath = System.IO.Path.Combine(path, filename);
                string entryName = filenameWithPath.Substring(folderOffset); // Makes the name in zip based on the folder
                entryName = ZipEntry.CleanName(entryName); // Removes drive from name and fixes slash direction
                ZipEntry newEntry = new ZipEntry(entryName);
                newEntry.DateTime = isf.GetLastWriteTime(filenameWithPath).DateTime; // Note the zip format stores 2 second granularity
    
                // To permit the zip to be unpacked by built-in extractor in WinXP and Server2003, WinZip 8, Java, and other older code,
                // you need to do one of the following: Specify UseZip64.Off, or set the Size.
                // If the file may be bigger than 4GB, or you do not need WinXP built-in compatibility, you do not need either,
                // but the zip will be in Zip64 format which not all utilities can understand.
                //   zipStream.UseZip64 = UseZip64.Off;
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filenameWithPath, System.IO.FileMode.Open, isf))
                {
                    newEntry.Size = stream.Length;
                }
    
                zipStream.PutNextEntry(newEntry);
    
                // Zip the file in buffered chunks
                // the "using" will close the stream even if an exception occurs
                byte[] buffer = new byte[4096];
                using (IsolatedStorageFileStream streamReader = isf.OpenFile(filenameWithPath, System.IO.FileMode.Open))
                {
                    StreamUtils.Copy(streamReader, zipStream, buffer);
                }
                zipStream.CloseEntry();
            }
            string[] folders = isf.GetDirectoryNames(System.IO.Path.Combine(path, "*.*"));
            foreach (string folder in folders)
            {
                CompressFolder(System.IO.Path.Combine(path, folder), zipStream, folderOffset, isf);
            }
        }
    
        // Compresses the files in the nominated folder, and creates a zip file on disk named as outPathname.
        //
        public void CreateZip(string outPathname, string password, string folderName)
        {
    
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fsOut = new IsolatedStorageFileStream(outPathname, System.IO.FileMode.Create, isf))
                {
                    ZipOutputStream zipStream = new ZipOutputStream(fsOut);
    
                    zipStream.SetLevel(3); //0-9, 9 being the highest level of compression
    
                    zipStream.Password = password;  // optional. Null is the same as not setting.
    
                    // This setting will strip the leading part of the folder path in the entries, to
                    // make the entries relative to the starting folder.
                    // To include the full path for each entry up to the drive root, assign folderOffset = 0.
    
                    // int folderOffset = folderName.Length + (folderName.EndsWith("\\") ? 0 : 1); // hu: currently not used for WP7 sample
                    int folderOffset = 0;
    
                    CompressFolder(folderName, zipStream, folderOffset, isf);
    
                    zipStream.Close();
                }
            }
        }
    
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                isf.CreateDirectory(@"root");
                isf.CreateDirectory(@"root\subfolder1");
                isf.CreateDirectory(@"root\subfolder2");
    
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(@"root\file0.txt", System.IO.FileMode.Create, isf))
                {
                    byte[] bytes = Encoding.Unicode.GetBytes("hello");
                    stream.Write(bytes, 0, bytes.Length);
                }
    
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(@"root\subfolder1\file1.txt", System.IO.FileMode.Create, isf))
                {
                    byte[] bytes = Encoding.Unicode.GetBytes("zip");
                    stream.Write(bytes, 0, bytes.Length);
                }
    
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(@"root\subfolder2\file2.txt", System.IO.FileMode.Create, isf))
                {
                    byte[] bytes = Encoding.Unicode.GetBytes("world");
                    stream.Write(bytes, 0, bytes.Length);
                }
    
            }
            CreateZip("root.zip", null, "root");
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems using CSS and margins. I have a list that the
Have you any problems using it on high concurrency environment? It's really works as
I have created a small application using Microsoft .NET. I don't have problems with
I have some problems sending mails through SMTP using Spring's MailSender interface and the
The post summarizes problems in using Screen in Mac's terminal when you have the
I am using the new ASP control Chart, but I have some problems with
I am using Pyme to interface with GPGME and have had no problems signing
We have some performance problems with one of our applications. I thought about using
I have problems using a shared library that was linked against a shared library.
What's new in jQuery(including UI) and will I have problems(using UI dialog and datepicker)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.