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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:44:22+00:00 2026-06-17T04:44:22+00:00

Hi I am having a button in my WPF application which extracts set of

  • 0

Hi I am having a button in my WPF application which extracts set of files from a zip. I need to work with a file in the extracted folder. But after extraction if i access that file i keep getting an exception stating that “File has been used by other process, can’t access” like that.
I used Stream.flush(), Stream.Close(), Stream.Dispose(). None of them is usefull.

var zipFilePath = @"C:\Output.zip";
var tempFolderPath = @"C:\Unzipped";


    using (Package package = ZipPackage.Open(zipFilePath, FileMode.Open, FileAccess.Read))
    {
        foreach (PackagePart part in package.GetParts())
        {

            var target = Path.GetFullPath(Path.Combine(tempFolderPath, part.Uri.OriginalString.TrimStart('/')));
            var targetDir = target.Remove(target.LastIndexOf('\\'));

            if (!Directory.Exists(targetDir))
                Directory.CreateDirectory(targetDir);
            MemoryStream memoryStream = new MemoryStream(); 
           using (Stream source = part.GetStream(FileMode.Open, FileAccess.Read))
           // using (Stream source = new FileStream(, FileMode.Open)) 
            {

              source.CopyTo(File.OpenWrite(target));
            //   CopyStreamTo(source, memoryStream); 
             }
        }

    }


    MessageBox.Show("Extracted in a folder");

          myclass obj=new myclass(@"C:\Unzipped\Something.xml");
        // Something.xml has been used by some other process  

Extraction works fine. But after extraction when i access file in C:\Unzipped\something.xml i keep getting this error.”The process cannot access the file ‘C:\Unzipped\Something.xml’ because it is being used by another process.”
How can i solve it??

  • 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-17T04:44:23+00:00Added an answer on June 17, 2026 at 4:44 am

    You should dispose IDisposable resources by wrapping them in using statements:

    using (Package package = ZipPackage.Open(zipFilePath, FileMode.Open, FileAccess.Read))
    {
        foreach (PackagePart part in package.GetParts())
        {
            var target = Path.GetFullPath(Path.Combine(tempFolderPath, part.Uri.OriginalString.TrimStart('/')));
            var targetDir = target.Remove(target.LastIndexOf('\\'));
    
            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }
    
            using (Stream source = part.GetStream(FileMode.Open, FileAccess.Read))
            using (Stream targetFileStream = File.OpenWrite(target))
            {
                source.CopyTo(targetFileStream);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a big problem when calling a web service from my WPF application.
Having just added a new button in my web application, I get an error
I am working on a WPF application having lots of screens and every screen
I am having a strange behaviour in a small WPF application. I have one
Scenario: I have a WPF desktop application which will be distributed on different machines
This is a WPF/C# application and I'm having more of a design problem than
I'm having an issue with tabbing through the controls on a WPF application using
I am having some issues with WPF not fully repainting a button control when
Consider a listbox in WPF (MVVM) having a list of items(items are file names).If
The layout which i am inflating into the alertbuilder is having two button. But

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.