Unzipping a downloaded file?

D

Davej

A

Arne Vajhøj

So if I have a WebClient program download a zipped update file and
would then like to launch the Windows "Extract All" thingie on that
file, is that difficult? I see people claiming that sub-directories
are not supported, but I don't know what they are talking about. Are
they saying that the .Net function that C# provides can't really
access the same "Expand All" that Windows uses? Thanks.

http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/7120dac4-8fc5-4cde-ba69-5302251a0631

..NET framework does not support ZIP only GZIP. GZIP does not
do directories.

I can also recommend the #ZipLib.

I have attached a code snippet using that below.

Arne

================

using System;
using System.Collections;
using System.IO;

using ICSharpCode.SharpZipLib.Zip;

namespace E
{
public class Program
{
public static void Unzip(string fnm, string dir)
{
ZipFile zf = new ZipFile(fnm);
foreach(ZipEntry ze in zf)
{
string fullloc = Path.Combine(dir, ze.Name.Replace('/',
Path.DirectorySeparatorChar));
string locdir = Path.GetDirectoryName(fullloc);
if(!Directory.Exists(locdir))
{
Directory.CreateDirectory(locdir);
}

if(!fullloc.EndsWith(Path.DirectorySeparatorChar.ToString()))
{
Stream istm = zf.GetInputStream(ze);
Stream ostm = new FileStream(fullloc,
FileMode.CreateNew, FileAccess.Write);
byte[] b = new byte[100000];
int n;
while((n = istm.Read(b, 0, b.Length)) > 0)
{
ostm.Write(b, 0, n);
}
ostm.Close();
}
}
zf.Close();
}
public static void Main(string[] args)
{
Unzip(@"C:\e\z.zip", @"C:\e\zz");
}
}
}
 
D

Davej

So if I have a WebClient program download a zipped update file and
would then like to launch the Windows "Extract All" thingie on that
file, is that difficult? I see people claiming that sub-directories
are not supported, but I don't know what they are talking about. Are
they saying that the .Net function that C# provides can't really
access the same "Expand All" that Windows uses? Thanks.

.NET framework does not support ZIP only GZIP. GZIP does not
do directories.

I can also recommend the #ZipLib.

I have attached a code snippet using that below.

Arne

================

using System;
using System.Collections;
using System.IO;

using ICSharpCode.SharpZipLib.Zip;

[...]

}


Ok, much thanks! I will give this a try.
 

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