tags:

views:

3673

answers:

6

I need to periodically download, extract and save the contents of http://data.dot.state.mn.us/dds/det_sample.xml.gz to disk. Anyone have experience downloading gzipped files with C#?

+1  A: 

The GZipStream class might be what you want.

Patrick
+3  A: 

Just use the HttpWebRequest class in the System.Net namespace to request the file and download it. Then use GZipStream class in the System.IO.Compression namespace to extract the contents to the location you specify. They provide examples.

Dale Ragan
+4  A: 

You can use WebClient in System.Net to download:

WebClient Client = new WebClient ();
Client.DownloadFile("http://data.dot.state.mn.us/dds/det_sample.xml.gz", " C:\mygzipfile.gz");

then use #ziplib to extract

Edit: or GZipStream... forgot about that one

Adam Haile
+5  A: 

Try the SharpZipLib, a C# based library for compressing and uncompressing files using gzip/zip.

Sample usage can be found on this blog post:

using ICSharpCode.SharpZipLib.Zip;

FastZip fz = new FastZip();       
fz.ExtractZip(zipFile, targetDirectory,"");
Yaakov Ellis
+12  A: 

Here is a post I wrote last year that shows how to decompress a gzip file using C# and the built-in GZipStream class. http://blogs.msdn.com/miah/archive/2007/09/05/zipping-files.aspx

As for downloading it, you can use the standard WebRequest or WebClient classes in .NET.

JeremiahClark
+1 The link was helpful to me just now using compression for the first time. Nice, useful, concise blog entry.
J M
A: 

How do you download over SSL?

(I know this isnt an answer, but i didnt want to create a whole new ? out of this, i'd like to enhance this existing ?)

Scott Kramer
You should do a new question and refer to this one
John Sheehan
Better create a new one. Highjacking questions ain't nice!
Sam