ZIP files in C#

J

Jon Skeet [C# MVP]

Fabio said:
If you are using vs2005 you can also use the
System.IO.Compression.GZipStream class.

While that gives compression and will cope with gzip files, I don't
believe it'll help much with "normal" zip files.
 
J

Jon Skeet [C# MVP]

Jordan said:
Highly recommended: http://www.7-zip.org/
Here's their Sourceforge page: http://sourceforge.net/projects/sevenzip/

Two versions are available - one with a GUI and a compact (< 500K ) command
line version that you can execute from your code - passing in parameters for
what to zip (input and output file name).

And it's free.

Starting a separate process makes life a lot more complicated than
using a library from within your own code.
 
J

Jordan

RE:
<< ...a lot more complicated... >>

Can you explain? It seems pretty straight-forward to me.
 
N

Nick Malik [Microsoft]

Jon is right, Jordan. Calling a seperate app from your code creates a slew
of dependencies and issues for applications. I'd recommend against it.

Examples:
-- Customer A works for a large corporation that controls the manner in
which apps can be installed on the desktop. They review the install for
your app and, seeing that you are installing two executables instead of one,
simply refuse to allow the app to be installed. (= lost sale).

-- Customer B installs your app and then, the next day, downloads a zip file
sent from their customer. They double-click the zip file, as always, but
this time, a different app opens up to handle it because your zip app has
registered itself to handle files with the extension of .ZIP. They freak
out and call Customer Support in their company. After hours of frustration,
customer support figures out that the customer had installed your app, and
advises them to uninstall your app. They then place a rule in the corporate
knowledge base to advise everyone else to uninstall the app as well. (=
lost sale and lost reputation)

-- Customer C has a memory constrained environment. They run your app,
which attempts to decompress a large file. This takes a long time. Because
the zip app is external and async, your app thinks that the uncompression
has completed already and attempts to open the uncompressed file, which
fails. (= impression of code defects)

-- Customer D hears of a virus that has shown up and proactively searches on
their machine for files of a specific name. They find the zip program and
delete it. Your app simply starts to fail. (= impression of poor quality).

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Jordan said:
RE:
<< ...a lot more complicated... >>

Can you explain? It seems pretty straight-forward to me.
 
J

Jordan

Thanks Nick.

Your explanations and examples are all helpful. They all have to do with the
non technical aspects of calling another application. Granted, those "non
technical aspects" are critically important and reason enough, I'd agree, to
avoid calling another application in those and similar scenarios.

Mr. Skeet's advice, however, seemed to imply some *technical issues* with
calling another application (he wrote, "Starting a separate process...
[causes problems]"). If that was his meaning then I'd still be interested in
knowing any technical issues because I'm currently doing what he is advising
against. I have a simple Console app that gets executed by the Windows Task
Scheduler on a nightly basis. It looks for files in a folder and zips any
that are found as part of a data archiving routine. If there is some
technical issue with doing this I'd be very interested in knowing what they
are.

Thanks again!

-J



Nick Malik said:
Jon is right, Jordan. Calling a seperate app from your code creates a
slew of dependencies and issues for applications. I'd recommend against
it.

Examples:
-- Customer A works for a large corporation that controls the manner in
which apps can be installed on the desktop. They review the install for
your app and, seeing that you are installing two executables instead of
one, simply refuse to allow the app to be installed. (= lost sale).

-- Customer B installs your app and then, the next day, downloads a zip
file sent from their customer. They double-click the zip file, as always,
but this time, a different app opens up to handle it because your zip app
has registered itself to handle files with the extension of .ZIP. They
freak out and call Customer Support in their company. After hours of
frustration, customer support figures out that the customer had installed
your app, and advises them to uninstall your app. They then place a rule
in the corporate knowledge base to advise everyone else to uninstall the
app as well. (= lost sale and lost reputation)

-- Customer C has a memory constrained environment. They run your app,
which attempts to decompress a large file. This takes a long time.
Because the zip app is external and async, your app thinks that the
uncompression has completed already and attempts to open the uncompressed
file, which fails. (= impression of code defects)

-- Customer D hears of a virus that has shown up and proactively searches
on their machine for files of a specific name. They find the zip program
and delete it. Your app simply starts to fail. (= impression of poor
quality).

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
J

Jon Skeet [C# MVP]

Jordan said:
RE:
<< ...a lot more complicated... >>

Can you explain? It seems pretty straight-forward to me.

Starting separate processes is more complicated in terms of:

1) Redirecting standard output/error, depending on what the process
does
2) Capturing precise error information - an exception can be a lot more
useful than an error number
3) The options available - how would you open a zip file and read one
entry *in memory* using a separate process?
4) Security - who is the process going to run as? Will that user always
have enough permissions to do everything you'd be able to do within
the CLR if, say, impersonation is involved?
5) Security the other way round - perhaps the process will end up with
*more* permissions than the .NET sandboxed process.


Libraries are just a lot easier to work with than separate processes,
unless all you want to do is exactly what the other program would do.
 
J

Jon Skeet [C# MVP]

TerryFei said:
I hope the following article will be helpful for you:
Title: ZIP Code Utility
URL: http://www.codeproject.com/csharp/zipcodeutil.asp

Thanks and have a nice day!

Wrong kind of zip. From the first line of the article:

<quote>
This article provides an easy method to lookup a U.S. City/State by ZIP
Code, or one or more ZIP Codes by City/State.
</quote>

In other words, nothing to do with zip *files*.

Jon
 
T

TerryFei

Hi ,

Sorry, I have misunderstood the meaning. Based on my knowledge, if we want
to compress file , we can use ZLIB library to achieve it.
I also hope the following article will be helpful:
Title: Compress Zip files with Windows Shell API and C#
URL:http://www.codeproject.com/csharp/compresswithwinshellapics.asp


Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
From: "Jon Skeet [C# MVP]" <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.csharp
Subject: Re: ZIP files in C#
Date: 13 Mar 2006 00:07:44 -0800
Organization: http://groups.google.com
Lines: 18
Message-ID: <[email protected]>
References: <[email protected]>
<[email protected]>
NNTP-Posting-Host: 213.146.158.130
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1142237271 11332 127.0.0.1 (13 Mar 2006 08:07:51 GMT)
X-Complaints-To: (e-mail address removed)
NNTP-Posting-Date: Mon, 13 Mar 2006 08:07:51 +0000 (UTC)
In-Reply-To: <[email protected]>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8)
Gecko/20051111 Firefox/1.5,gzip(gfe),gzip(gfe)
 
A

AlexL [Xceed]

Starting a separate process makes life a lot more complicated than
using a library from within your own code.

Also, you might want to have an entirely managed solution, as well, so
when looking for a .NET Zip compression component, be sure you don't
fall into the trap of thinking you purchased a .NET Zip component but
it is actually just a .NET wrapper over unmanaged code. Only the most
reputable companies offer this (Xceed, Dart, /n Software) and also
sharpZipLib, if you have more time on your hands or don't need
advanced capabilities (like support for more than 4GB, immediate help
by email, great documentation, etc.)



--
Alex Leblanc
Xceed Software Inc.
http://www.xceedsoft.com

Check out our advanced .NET grid and Windows Forms UI controls

Email: (e-mail address removed) (remove the first 'x')
 

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