Mutiple files compression into a single Archive file

M

Mohan

Hi,

I would like to compress multiple files in to a single Archive file.

The Archive file should be in the standard format so that I can open the
same using the standard Zip tools like WinZip etc..

Please suggest me on this how to go ahead..



Thanks & Regards,
Mohan
 
M

Mohan

Thanks Peter for the same.. Could you advise me any third party library for
the same..
 
A

Arne Vajhøj

I would like to compress multiple files in to a single Archive file.

The Archive file should be in the standard format so that I can open the
same using the standard Zip tools like WinZip etc..

..NET out of the box only supports single file compression (GZIP).

Get an extra library like SharpZipLib for creating zip files.

I can find some examples for that library if needed.

Arne
 
T

Tom Shelton

Peter Duniho explained on 9/28/2010 :
Find a third-party library that will handle the .zip format? Alternatively,
execute pkzip.exe or something similar as an external process to do the work.

AFAIK, .NET has no support for the .zip container format.

Pete

Actually, it does... Via the System.IO.Packaging namespace...

using System;
using System.IO;
using System.IO.Packaging;

namespace ConsoleApplication85
{
class Program
{
static void Main ( string[] args )
{
string path = Path.Combine (
Environment.GetFolderPath ( Environment.SpecialFolder.MyDocuments ),
"Beehive Plans" );

using ( Package pkg = ZipPackage.Open ( "beehive.zip", FileMode.Create ) )
{
foreach ( string file in Directory.GetFiles ( path ) )
{
PackagePart part = pkg.CreatePart (
new Uri ( "/" + Path.GetFileName(file), UriKind.Relative ),
System.Net.Mime.MediaTypeNames.Application.Octet,
CompressionOption.Maximum );
byte[] content = File.ReadAllBytes ( file );
part.GetStream ().Write ( content, 0, content.Length );
}
}
}
}
}

But, in can be a bit tricky about mime types - I tend to use sharpziplib
instead :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top