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

[{'answer_id': 16841, 'author': 'Patrick', 'author_id': 429, 'author_profile': 'https://Stackoverflow.com/users/429', 'pm_score': 2, 'selected': False, 'text': '<p>The <a href="http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx" rel="nofollow noreferrer">GZipStream</a> class might be what you want.</p>\n'}, {'answer_id': 16842, 'author': 'Dale Ragan', 'author_id': 1117, 'author_profile': 'https://Stackoverflow.com/users/1117', 'pm_score': 2, 'selected': False, 'text': '<p>Just use the <a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx" rel="nofollow noreferrer">HttpWebRequest</a> class in the System.Net namespace to request the file and download it.  Then use <a href="http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx" rel="nofollow noreferrer">GZipStream</a> class in the System.IO.Compression namespace to extract the contents to the location you specify.  They provide examples.</p>\n'}, {'answer_id': 16852, 'author': 'Adam Haile', 'author_id': 194, 'author_profile': 'https://Stackoverflow.com/users/194', 'pm_score': 3, 'selected': False, 'text': '<p>You can use WebClient in System.Net to download:</p>\n\n<pre><code>WebClient Client = new WebClient ();\nClient.DownloadFile("http://data.dot.state.mn.us/dds/det_sample.xml.gz", " C:\\mygzipfile.gz");\n</code></pre>\n\n<p>then use <a href="http://sharpdevelop.net/OpenSource/SharpZipLib/Default.aspx" rel="noreferrer">#ziplib</a> to extract</p>\n\n<p>Edit: or GZipStream... forgot about that one</p>\n'}, {'answer_id': 16853, 'author': 'Yaakov Ellis', 'author_id': 51, 'author_profile': 'https://Stackoverflow.com/users/51', 'pm_score': 3, 'selected': False, 'text': '<p>Try the <a href="http://www.icsharpcode.net/OpenSource/SharpZipLib/" rel="nofollow noreferrer">SharpZipLib</a>, a C# based library for compressing and uncompressing files using gzip/zip.</p>\n\n<p>Sample usage can be found on this <a href="http://dotnet.org.za/thea/archive/2006/01/17/Unzip-files-programmatically-in-C_2300_-_2D00_-_2300_ZipLib.aspx" rel="nofollow noreferrer">blog post</a>:</p>\n\n<pre><code>using ICSharpCode.SharpZipLib.Zip;\n\nFastZip fz = new FastZip();       \nfz.ExtractZip(zipFile, targetDirectory,"");\n</code></pre>\n'}, {'answer_id': 16856, 'author': 'JeremiahClark', 'author_id': 581, 'author_profile': 'https://Stackoverflow.com/users/581', 'pm_score': 6, 'selected': True, 'text': '<p>To compress:</p>\n\n<pre><code>using (FileStream fStream = new FileStream(@"C:\\test.docx.gzip", \nFileMode.Create, FileAccess.Write)) {\n    using (GZipStream zipStream = new GZipStream(fStream, \n    CompressionMode.Compress)) {\n        byte[] inputfile = File.ReadAllBytes(@"c:\\test.docx");\n        zipStream.Write(inputfile, 0, inputfile.Length);\n    }\n}\n</code></pre>\n\n<p>To Decompress:</p>\n\n<pre><code>using (FileStream fInStream = new FileStream(@"c:\\test.docx.gz", \nFileMode.Open, FileAccess.Read)) {\n    using (GZipStream zipStream = new GZipStream(fInStream, CompressionMode.Decompress)) {   \n        using (FileStream fOutStream = new FileStream(@"c:\\test1.docx", \n        FileMode.Create, FileAccess.Write)) {\n            byte[] tempBytes = new byte[4096];\n            int i;\n            while ((i = zipStream.Read(tempBytes, 0, tempBytes.Length)) != 0) {\n                fOutStream.Write(tempBytes, 0, i);\n            }\n        }\n    }\n}\n</code></pre>\n\n<p>Taken from a post I wrote last year that shows how to decompress a gzip file using C# and the built-in GZipStream class.\n<a href="http://blogs.msdn.com/miah/archive/2007/09/05/zipping-files.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/miah/archive/2007/09/05/zipping-files.aspx</a></p>\n\n<p>As for downloading it, you can use the standard <a href="http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx" rel="nofollow noreferrer">WebRequest</a> or <a href="http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx" rel="nofollow noreferrer">WebClient</a> classes in .NET. </p>\n'}, {'answer_id': 70603695, 'author': 'Ajai Rajendran', 'author_id': 17847889, 'author_profile': 'https://Stackoverflow.com/users/17847889', 'pm_score': 0, 'selected': False, 'text': '<p>You can use the <code>HttpContext</code> object to download a csv.gz file</p>\n<p>Convert you <code>DataTable</code> into string using <code>StringBuilder</code> (<code>inputString</code>)</p>\n<pre><code>byte[] buffer = Encoding.ASCII.GetBytes(inputString.ToString());\nHttpContext.Current.Response.Clear();\nHttpContext.Current.Response.Buffer = true;\nHttpContext.Current.Response.ContentType = &quot;application/zip&quot;;\nHttpContext.Current.Response.AddHeader(&quot;Content-Disposition&quot;, string.Format(&quot;attachment;filename={0}.csv.gz&quot;, fileName));\nHttpContext.Current.Response.Filter = new GZipStream(HttpContext.Current.Response.Filter, CompressionMode.Compress);\nHttpContext.Current.Response.AppendHeader(&quot;Content-Encoding&quot;, &quot;gzip&quot;);\nusing (GZipStream zipStream = new GZipStream(HttpContext.Current.Response.OutputStream, CompressionMode.Compress))\n{\n    zipStream.Write(buffer, 0, buffer.Length);\n}\nHttpContext.Current.Response.End();\n</code></pre>\n<p>You can extract this downloaded file using 7Zip</p>\n'}]
['https://Stackoverflow.com/questions/16833', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1786/']