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 8036783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:44:05+00:00 2026-06-05T02:44:05+00:00

When using DotNetZip, is it possible to get what the final zip file size

  • 0

When using DotNetZip, is it possible to get what the final zip file size will be before calling Save(stream)? I have a application(Window Service) where package Stream size is more than 100MB then package will saved and upcoming files add into new package.

I got same question for web application but not understand the answer. Is there any way into DotnetZip to find the size of zip stream before save on I/O system?

  • 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-06-05T02:44:07+00:00Added an answer on June 5, 2026 at 2:44 am

    I got the solution. Here is code.Now I will create the package which size is less then 100MB.

    using System;
    using System.Collections;
    using System.IO;
    using Ionic.Zip;
    using Ionic.Zlib;
    
    namespace ZipFileSize1
    {
        /// <summary>
        /// This source code is generate the specified size Packages from the directory.
        /// </summary>
        class Program
        {
            /// <summary>
            /// The size of Package(100MB).
            /// </summary>
            public static long m_packageSize = 1024 * 1024 * 100;
    
            /// <summary>
            ///  Main method of program class.
            /// </summary>
            /// <param name="args">Command line argument</param>
            static void Main(string[] args)
            {
                Console.WriteLine("Enter Directory Full Name for Compression : ");
                var dir = Console.ReadLine();
                Console.WriteLine("Zip File saved Location Directory Name : ");
                var savedir = Console.ReadLine();
    
                //generate the random zip files.
    
                var zipFile = Path.Combine(savedir, DateTime.Now.Ticks + ".zip");
                ZipFiles(dir, savedir);
    
                Console.ReadLine();
            }
    
            /// <summary>
            /// This method generate the package as per the <c>PackageSize</c> declare.
            /// Currently <c>PackageSize</c> is 100MB.
            /// </summary>
            /// <param name="inputFolderPath">Input folder Path.</param>
            /// <param name="outputFolderandFile">Output folder Path.</param>
            public static void ZipFiles(string inputFolderPath, string outputFolderandFile)
            {
                ArrayList ar = GenerateFileList(inputFolderPath); // generate file list
                int trimLength = (Directory.GetParent(inputFolderPath)).ToString().Length;
                // find number of chars to remove   // from original file path
                trimLength += 1; //remove '\'
    
                // Output file stream of package.
                FileStream ostream;
                byte[] obuffer;
    
                // Output Zip file name.
                string outPath = Path.Combine(outputFolderandFile, DateTime.Now.Ticks + ".zip");
    
                ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outPath), true); // create zip stream
    
                // Compression level of zip file.
                oZipStream.CompressionLevel = CompressionLevel.Default;
    
                // Initialize the zip entry object.
                ZipEntry oZipEntry = new ZipEntry();
    
                // numbers of files in file list.
                var counter = ar.Count;
                try
                {
                    using (ZipFile zip = new ZipFile())
                    {
                        Array.Sort(ar.ToArray());  // Sort the file list array.
                        foreach (string Fil in ar.ToArray()) // for each file, generate a zip entry
                        {
                            if (!Fil.EndsWith(@"/")) // if a file ends with '/' its a directory
                            {
    
                                if (!zip.ContainsEntry(Path.GetFullPath(Fil.ToString())))
                                {
                                    oZipEntry = zip.AddEntry(Path.GetFullPath(Fil.ToString()), Fil.Remove(0, trimLength));
                                    counter--;
                                    try
                                    {
                                        if (counter > 0)
                                        {
                                            if (oZipStream.Position < m_packageSize)
                                            {
                                                oZipStream.PutNextEntry(oZipEntry.FileName);
                                                ostream = File.OpenRead(Fil);
                                                obuffer = new byte[ostream.Length];
                                                ostream.Read(obuffer, 0, obuffer.Length);
                                                oZipStream.Write(obuffer, 0, obuffer.Length);
                                            }
    
                                            if (oZipStream.Position > m_packageSize)
                                            {
                                                zip.RemoveEntry(oZipEntry);
                                                oZipStream.Flush();
                                                oZipStream.Close(); // close the zip stream.
                                                outPath = Path.Combine(outputFolderandFile, DateTime.Now.Ticks + ".zip"); // create new output zip file when package size.
                                                oZipStream = new ZipOutputStream(File.Create(outPath), true); // create zip stream                                                
                                            }
                                        }
                                        else
                                        {
                                            Console.WriteLine("No more file existed in directory");
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                        zip.RemoveEntry(oZipEntry.FileName);
                                    }
    
                                }
                                else
                                {
                                    Console.WriteLine("File Existed {0} in Zip {1}", Path.GetFullPath(Fil.ToString()), outPath);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
    
                }
                finally
                {
                    oZipStream.Flush();
                    oZipStream.Close();// close stream
                    Console.WriteLine("Remain Files{0}", counter);
                }
            }
    
            /// <summary>
            /// This method return the list of files from the directory
            /// Also read the child directory also, but not add the 0 length file.
            /// </summary>
            /// <param name="Dir">Name of directory.</param>
            /// <returns>return the list of all files including into subdirectory files </returns>
            private static ArrayList GenerateFileList(string Dir)
            {
                ArrayList fils = new ArrayList();
    
                foreach (string file in Directory.GetFiles(Dir, "*.*", SearchOption.AllDirectories)) // add each file in directory
                {
                    if (File.ReadAllBytes(file).Length > 0)
                        fils.Add(file);
                }
    
                return fils; // return file list
            }      
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a zip file and save it using DotNetZip library.
We are developing an application that uploads large files over Internet. File size before
I have a bunch of AES256-encrypted ZIP containers (using DotNetZip), and I am writing
I'm using DotNetZip to create a zip file and pass it to a FileResult.
I'm trying to make a method of compressing file using Ionic.Zip.dll of DotNetZip. Code
I'm using DotNetZip to add a file to a zip archive, which I've read
I completely fail to get dotnetzip to add files to a .zip file i
Using Java,I have to fetch multiple sets of values from an XML file to
i use DotNetZip in my project. using (var zip = new ZipFile()) { zip.ProvisionalAlternateEncoding
I am using DotNetZip and have noticed that i am getting permission issues on

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.