views:

1160

answers:

5

I like to zip multiple files which are being created dynamically in my web application. Those files should be zipped. For this, i dont want to use any third-party tools. just like to use .net api in c#

+2  A: 

http://www.codeplex.com/DotNetZip Source codes are available, so you can see how they do it and write something similiar for yourself

Ray
A: 

Check out System.IO.Compression.DeflateStream. Youll find a couple of examples on msdn http://msdn.microsoft.com/en-us/library/system.io.compression.deflatestream.aspx

Marcom
Deflate is not ZIP. There is also GZipStream but it's also not ZIP.
Ray
true, but you can still compress multiple files together for sending. Sarathi asked for something inbuilt in .net. And thats one thing that .net offers
Marcom
+5  A: 

I'm not sure what you mean by not wanting to use thrid party tools, but I assume its that you don't want some nasty interop to programmatically do it through another piece of software.

I recommend using ICSharpCode SharpZipLib

This can be added to your project as a reference DLL and is fairly straightforward for creating ZIP files and reading them.

ck
SharpZipLib is good (+1) but you can do it natively in .Net now - see @Ruben Bartelink's answer
Keith
@Keith - only if you've moved onto .Net 3.0+
ck
He didnt exclude .NET 3, and its hardly as big as forcing a move from .NET 1.1 to 2.0 - Though SharpZipLib is a fine library that's heavily used (inc by me)
Ruben Bartelink
@Ruben - obviously yours is a highly valid answer (+1), but moving from 2.0 to 3.0+ isn't just about the technical changes, there's all the bureaucracy involved with licensing etc.
ck
@ck: Not sure what licensing you're referring to, but surely you dont want to be living without System.Core :P (My main point was that the questioner didnt specifically rule out .NET 3.0, but made noises in the direction of wanting to use only MS stuff)
Ruben Bartelink
@Ruben - for licensing I mean moving to Visual Studio 2008 in all our development environments.
ck
@ck - .NET 3.0 is just a framework update, you don't need VS2008 to exploit its goodness.
Kev
@Kev - my dev machine is patched up to 3.5, how do I get to use the 3.0 changes in VS 2005?
ck
@ck - follow Eric Moreau's steps in Ruben's link. All you need to do is add a reference to the WindowsBase assembly. Works just fine in VS2005.
Kev
And it is the ugliest programming model for ZIP files, ever.
Cheeso
+15  A: 

Use System.IO.Packaging in .NET 3.0+.

See this introduction to System.IO.Packaging

Ruben Bartelink
+1, beat me to it!
Keith
@Keith: thankfully you didnt post / deleted your post unlike some!
Ruben Bartelink
Just a note: This is the ugliest API ever, for zipping.
Cheeso
A: 

You could always call a third-party executable like 7-zip with an appropriate command line using the System.Diagnostics.Process class. There's no interop that way because you're just asking the OS to launch a binary.

ajs410