Extract Specific Files with C# Windows Form

Asked

Viewed 31 times

-2

Boa Tarde Personal,

I have a question and I hope you can help me.

I added to my project a ZIP file with files inside. I need to compile this zip file along with the program. After compiling the program, by clicking a button, the program will extract the files that are inside the ZIP file in a specific folder.

I would like to know what code to use to carry out such a process.

1 answer

0


Good afternoon Andrey What would I do in that case:

  1. Rename . zip file to another extension. (Ex. data, . bin, etc...)
  2. I would change the property "Copy to Output Directory" to "Copy Always", so the file will always go to your output directory at build and Publish time
  3. Now your application can unzip the file using the System.IO.Compression.Zipfile class(https://docs.microsoft.com/pt-br/dotnet/api/system.io.compression.zipfile?view=netframework-4.8).

Obs. I’m not sure that the Zipfile class can unzip files with an extension other than .zip. If you have a problem with this, simply rename the file using System.IO.File.Move (https://docs.microsoft.com/pt-br/dotnet/api/system.io.file.move?view=netframework-4.8)

This may seem like a gambiarra, but it is not such an unusual practice, after all nuget files themselves are . zip with another extension.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.