Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, September 20, 2016 2:02 PM
Hello,
How can i extract data from .Z files?. WinRar Archive and ZipFile do not work for that type.
I tried to use this namespace using Ebixio.LZW; but it gives me type or namespace does not exist. Is there an example to show how can i read data from .Z file in C# (Visual Studio 2013, .NET 4.5.1)
Thanks
All replies (11)
Sunday, September 25, 2016 3:13 PM âś…Answered
Hi HeshamVoda,
For your question, the following code could decompress .z file. I tried it. It works on my computer.
Please reference the System.IO.Compression.FileSystem assembly in your project.
If it could not extract your .z file, could you please provide your file for us to give you a solution?
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Compression;
namespace extract.z_file
{
class Program
{
static void Main(string[] args)
{
string zipPath = @"C:\Users\Wendy\Desktop\New.z";
string extractPath = @"C:\Users\Wendy\Desktop\extract";
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
}
Here is the output.
I hope this would be helpful to you.
If you have something else, please feel free to contact us.
Best Regards,
Wendy
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Tuesday, September 20, 2016 2:18 PM
Hi Heshma,
Have you tried using DotNetZip library? Hope this helps you.
Thanks,
Sabah Shariq
Tuesday, September 20, 2016 2:25 PM
DotNetZip does not work for .Z files. .Z files are unix compressed files
Tuesday, September 20, 2016 2:55 PM
DotNetZip does not work for .Z files. .Z files are unix compressed files
That compression is specific for Unix first and foremost. I have no data wich type of compression it even uses (if it is even only one). Once you know the Algorythm, you can look if any class exists.
However it appears that 7-zip can unpack it, wich is propably your best bet.
You are free to distribute 7-zip and any parts of it along with your programm. And once it is around (installed or not) you have 2 ways to control it:
You can control 7-zip via Commandline redirection or by using the COM interface on the DLL. Or use this wrapper around the COM interface on the dll:
https://sevenzipsharp.codeplex.com/
Edit:
According to Wikipedia, compress is "based on the LZW algorythm".
There appears to be no 1st party implementation of LZW in .NET, except maybe a few Image related classes (as GIF is based on LZW too). However 3rd party solutions are avalible:
http://stackoverflow.com/questions/8713850/lzw-data-compression
Remember to mark helpfull answers as helpfull and close threads by marking answers.
Tuesday, September 20, 2016 4:20 PM | 1 vote
For managed code you can use SharpLZW. It is supposed to support .z files.
There is also a VB.NET example here.
I have tried neither of these libraries so you'll need to work on this yourself. Questions should be posted to the providers of those libraries.
Michael Taylor
http://www.michaeltaylorp3.net
Tuesday, September 20, 2016 5:40 PM
Hello,
Everyone that has replied has pointed you in the correct direction for possible solutions.
However, I would like you to keep in mind that using the File Extension to determine the
internal file structure type is not proper. Some software developers will rename File
Extension that possibly no meaning to the actual structure of the file.
By reading the few Bytes of the file should help to determine if there is a known format
header present. Most compressed file will have some sort of ID at the beginning of the
file. Then, only then, will know "How To" handle the internal File Structure.
Just something for you to keep in mind while you are coding. Thanks :)
Wednesday, September 21, 2016 9:59 AM
Hi Hesham,
You could look into the solution below thread provided. What they are doing is using Process.Start() method where it is passing the installed WinZip .exe location and the .Z file path for extracting. Hope this helps you.
How to extract *.Z files using C# ?
Thanks,
Sabah Shariq
Wednesday, September 21, 2016 10:54 AM
Hi HeshamVoda,
Thank you for posting here.
For your question, could you please provide your .z file which could not unzip by WinRar Archive and ZipFile?
I have try to extract data from .Z file. However, the .Z file could be open by WinRAR.
More details could be helpful for us to give you a solution.
Thanks for your understanding and cooperation.
Wendy
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Tuesday, August 28, 2018 1:35 PM
Hi Wendy,
Tried to use System.IO.Compression in my .NET 4.7.1 app but no luck, VS2017 can't compile your sample. It says "The name 'ZipFile' does not exist in the current context"
Wednesday, January 9, 2019 12:37 PM
This does not works. There is no class ZipFile present in System.IO.Compression namespace. There is no such namespace as System.IO.Compression.FileSystem present.
Wednesday, January 9, 2019 12:47 PM
This does not works. There is no class ZipFile present in System.IO.Compression namespace.
.NET Framework 4.7.2 : ZipFile Class