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

  • SEARCH
  • Home
  • 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 6360569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:39:54+00:00 2026-05-24T23:39:54+00:00

I got this error Cannot access a closed file when I save more than

  • 0

I got this error “Cannot access a closed file” when I save more than one file in zip.
This is the code. Error at zip.Save(NewZipPath);

internal static string UpdateZipFile(string PdfPath, string ZipPath, 
                    string NewZipPath, string docPath)
{
    try
    {
    using (ZipFile zip = ZipFile.Read(ZipPath))
    {
        FileStream fs = new FileStream(PdfPath, FileMode.Open, FileAccess.Read);

        DirectoryInfo Dir = new DirectoryInfo(docPath);

        FileInfo[] FileList = Dir.GetFiles("*.*", SearchOption.AllDirectories);

        foreach (FileInfo FI in FileList)
        {
        zip.AddEntry(FI.FullName, fs);
        }

        // Error at this line if more than one
        // files in above directory.
        zip.Save(NewZipPath);

        fs.Close();
        fs.Dispose();

        return "- ZIP Generated Successfully !";
    }
    }
    catch (Exception ex)
    {
    return ex.Message;
    }
}

Full exception

System.ObjectDisposedException: Cannot access a closed file.
   at System.IO.__Error.FileNotOpen()
   at System.IO.FileStream.get_Length()
   at Ionic.Zip.ZipEntry.SetInputAndFigureFileLength(Stream& input)
   at Ionic.Zip.ZipEntry._WriteEntryData(Stream s)
   at Ionic.Zip.ZipEntry._EmitOne(Stream outstream)
   at Ionic.Zip.ZipEntry.Write(Stream s)
   at Ionic.Zip.ZipFile.Save()
   at Ionic.Zip.ZipFile.Save(String fileName)
   at RideShare.Utility.UpdateZipFile(String PdfPath, 
String ZipPath, String NewZipPath, String docPath) in 

Thanks.

  • 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-24T23:39:55+00:00Added an answer on May 24, 2026 at 11:39 pm

    I think what’s going on here is that the use of the stream “FS” is tangled up. You can spend time trying to untangle it, or you can use the simpler “AddFiles” method:

    Search for “Create a zip containing all the files in a folder.” at

    http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=Examples

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The other day I got this annoying oracle error: ORA-12705: Cannot access NLS data
I got this error Unhandled exception at 0x0049b946 in Program.exe: 0xC0000005: Access violation reading
Recently i got this error SecurityError: Error #2148: SWF file file:///C:/Users/SUN/Desktop/TriStateCheckBox2/bin-debug/index.swf cannot access local
I got this error today when trying to open a Visual Studio 2008 project
I got this error when I tried to compile an application that includes the
I got this error when trying to update an image. It was a cross-thread
I got this error for a collection I am writing, but fxcop warned me
I got this error twice. it says error: redefinition of '-[SampleTableViewController tableView:cellForRowAtIndexPath:]'
I got this error running a query that goes against 2 tables with combined
I got this error An error occurred while parsing EntityName. Line 1, position 61.

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.