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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:36:46+00:00 2026-06-15T17:36:46+00:00

My problem is : I need to write an application that zips one file.

  • 0

My problem is :

I need to write an application that zips one file.

The application successfully reads the file from an user defined location, but the trouble is, I can’t make it to write the archive file name to a specified folder without getting an annoying error : "The process cannot access the file 'C:\Users\bg\Desktop\1323.zip‘ because it is being used by another process.” at the line :
archiver.OpenArchive (System.IO.FileMode.Create);

Here is my c sharp code :

private void zipThatFileToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Stream myStream;
        SaveFileDialog saveFileDialog1 = new SaveFileDialog();

        saveFileDialog1.Filter = "zip files (*.zip)|*.zip|All files (*.*)|*.*";
        saveFileDialog1.FilterIndex = 1;
        saveFileDialog1.RestoreDirectory = true;

        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
        {
            if ((myStream = saveFileDialog1.OpenFile()) != null)
            {
                ZipForge archiver = new ZipForge();

                // The name of the ZIP file to be create
                string env = saveFileDialog1.FileName;
                //MessageBox.Show(env);

                //this doesn't work
                archiver.FileName = env;

                //this works
                //archiver.FileName = @"D:\test.zip";

                // Specify FileMode.Create to create a new ZIP file
                // or FileMode.Open to open an existing archive


                archiver.OpenArchive (System.IO.FileMode.Create);
                // Default path for all operations             
                archiver.BaseDir = @"C:\Users\bg\Desktop\";
                // Add file C:\file.txt the archive; wildcards can be used as well
                archiver.AddFiles(openFileDialog1.FileName);
                // Close archive
                archiver.CloseArchive();
                MessageBox.Show("The archive was created! ");
                myStream.Close();
            }
        }

I’m using this http://www.componentace.com/zip-file-in-c-sharp.htm with this http://www.componentace.com/zip-file-in-c-sharp.htm

  • 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-15T17:36:47+00:00Added an answer on June 15, 2026 at 5:36 pm

    I can’t say for sure, but it looks as if you’re trying to open the same file twice — first when you call "myStream = saveFileDialog1.OpenFile()) != null"

    , and again when you call "archiver.OpenArchive (System.IO.FileMode.Create);"

    I’d suggest perhaps closing myStream before you start your archive operations.

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

Sidebar

Related Questions

Problem I have a UDPlistener application that I need to write a unit test
Problem: I need to write/read objects from a file.This because I need to write/read
Here is the problem... For school project I need to write parallel application using
I need to write application which will be reeding data from InputStream. In short:
I have a slow MySQL query in my application that I need to re-write.
I have an WPF application. The problem: need program(daemon, service) that send signals by
I have a clojure application that need some configuration variable, mainly string but also
I'm writing an application that needs to create a special user account hidden from
I need to write an application in C# and VS2010 that can listen to
My problem comes from real practice: I have an application, that depends on external

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.