Hi,
I've
been watching around for a while now but in the end came up with
nothing. I want to write an application in C# .NET 2.0 that can handle
ZIP files. It must read any files from archives into memory or disk
files and create new archives from files on the disk and from memory.
I
have read and tested the J# article from supposedly 2 years ago but
failed with the writing to memory part due to incompatibilities between
C# and J#. (That CLR is not so common after all.) Also requiring another runtime for my little tool seems a
bit too much.
Then I took a brief look at #ziplib but it seems that
code isn't even half finished. From the very spare documentation I
found it cannot even add files to a ZIP archive - what good is that
Also the DLL seems to be over 100kB alone which would probably be 3x of
my functional code.
Then I tried for the 7zip SDK but it seems that one can only handle LZMA files, but I need plain old ZIPs. They're faster anyway and that counts more for me now.
My last try went for a zlib wrapper, but I'd need another thousand tools only to compile it.
Then
I searched this forum and found some System.IO.Compression but it looks
like it can only handle single files (streams) and no file collections like in
ZIP files. So that doesn't help me either.
A Google search only brought really expensive commercial products in addition.
Is really nobody of
you dealing with ZIP files ever since .NET I thought it would be just
as easy as almost anything else in .NET (2.0) but this seems to be the
point where it ends.
I previously wrote my app in VC++6 but it
became no more than a console app, decent window handling is way too
complicated in that old language. And the external 7za interface is unreliable so I need something integrated. VB can't even efficiently handle files
bytewise and Java looks ugly (windows and code) and is slow (runtime and IDE).
Can anyone help me with that
PS: Going back to edit from preview loses all the text I entered here in the forum. Seems a bit more than buggy like this. (Using Firefox 1.5)

Can I use ZIP files in C#?
RichardTM
- Require J# runtime and handle language barrier problems
- Use the bulky and unfinished #ziplib
- Spend tons of money for a commercial lib of unknown quality
- Build a bridge to some native DLLs
- Don't use compression
Also all this knowledge seems to base on the old .NET 1.1. Since .NET 2.0 comes with Deflate and GZip streams, can't they be used for building and reading ZIP files Shouldn't it be just a little ZIP header structure to it Has anybody a deeper knowledge of those things, could help me with a .NET 2 based ZIP library or is even already working on oneJonathan Howard
Macrop
u can attach this method to your code
private void zip(string[] args){
//Create an empty zip file byte[] emptyzip = new byte[] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; FileStream fs = File.Create(args[1]);fs.Write(emptyzip, 0, emptyzip.Length);
fs.Flush();
fs.Close();
fs =
null; //Copy a folder and its contents into the newly created zip fileShell32.
ShellClass sc = new Shell32.ShellClass(); // returns a Folder of args parameterShell32.
Folder SrcFlder = sc.NameSpace(args[0]);Shell32.
Folder DestFlder = sc.NameSpace(args[1]);Shell32.
FolderItems items = SrcFlder.Items();DestFlder.CopyHere(items, 0);
//Ziping a file using the Windows Shell API creates another thread where the zipping is executed. //This means that it is possible that this console app would end before the zipping thread //starts to execute which would cause the zip to never occur and you will end up with just //an empty zip file. So wait a second and give the zipping thread time to get startedSystem.Threading.
Thread.Sleep(1000);}
and then u call this method
string[] str = new string[2];str[0] = zipFolderPath; //zipFolderPath where you want to attachment zip file is added
str[1] = _startUpPath +
"\\" + "Attachment.zip"; //path contain zip filezip(str); //call zip method.
Hope this help.
Steven
sql server user
And as I said, a lot of expensive libraries, in this case 350(US )$. I won't spend any money for that.
tjcbs
no I havent done multifile archives with #zip, Ive only used it for stream compression, but the example indicates it does multifile.
I've had no problems with it. Yes it is a little large as it seems to do it all. I am sure you could whittle out the parts you don't need.