<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jesal gadhia &#187; sharpziplib</title>
	<atom:link href="http://jesal.us/tag/sharpziplib/feed/" rel="self" type="application/rss+xml" />
	<link>http://jesal.us</link>
	<description></description>
	<lastBuildDate>Fri, 19 Mar 2010 05:32:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to unzip files in .NET using SharpZipLib</title>
		<link>http://jesal.us/2008/03/how-to-unzip-files-in-net-using-sharpziplib/</link>
		<comments>http://jesal.us/2008/03/how-to-unzip-files-in-net-using-sharpziplib/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 06:30:22 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[sharpziplib]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/2008/03/12/how-to-unzip-files-in-net-using-sharpziplib/</guid>
		<description><![CDATA[SharpZipLib is a great open source library for handeling all kinds of gzip/zip compression/decompression. More Info &#8211; http://www.icsharpcode.net/OpenSource/SharpZipLib/
In the following example I&#8217;m passing the HtmlInputFile object directly into the ZipInputStream to decompress the PostedFile and save its contents on the server.


.
.
using System.IO;
using ICSharpCode.SharpZipLib.Zip
.
.
private void UnzipAndSave(HtmlInputFile objFileUpload)
{
    ZipInputStream s = new ZipInputStream(objFileUpload.PostedFile.InputStream);

    ZipEntry theEntry;
 [...]]]></description>
			<content:encoded><![CDATA[<p>SharpZipLib is a great open source library for handeling all kinds of gzip/zip compression/decompression. More Info &#8211; <a href="http://www.icsharpcode.net/OpenSource/SharpZipLib/">http://www.icsharpcode.net/OpenSource/SharpZipLib/</a></p>
<p>In the following example I&#8217;m passing the HtmlInputFile object directly into the ZipInputStream to decompress the PostedFile and save its contents on the server.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
.
.
<span class="kwrd">using</span> System.IO;
<span class="kwrd">using</span> ICSharpCode.SharpZipLib.Zip
.
.
<span class="kwrd">private</span> <span class="kwrd">void</span> UnzipAndSave(HtmlInputFile objFileUpload)
{
    ZipInputStream s = <span class="kwrd">new</span> ZipInputStream(objFileUpload.PostedFile.InputStream);

    ZipEntry theEntry;
    <span class="kwrd">string</span> virtualPath = <span class="str">"~/uploads/"</span>;
    <span class="kwrd">string</span> fileName = <span class="kwrd">string</span>.Empty;
    <span class="kwrd">string</span> fileExtension = <span class="kwrd">string</span>.Empty;
    <span class="kwrd">string</span> fileSize = <span class="kwrd">string</span>.Empty;

    <span class="kwrd">while</span> ((theEntry = s.GetNextEntry()) != <span class="kwrd">null</span>)
    {
        fileName = Path.GetFileName(theEntry.Name);
        fileExtension = Path.GetExtension(fileName);

        <span class="kwrd">if</span> (!<span class="kwrd">string</span>.IsNullOrEmpty(fileName))
        {
            <span class="kwrd">try</span>
            {
                FileStream streamWriter = File.Create(Server.MapPath(virtualPath + fileName));
                <span class="kwrd">int</span> size = 2048;
                <span class="kwrd">byte</span>[] data = <span class="kwrd">new</span> <span class="kwrd">byte</span>[2048];

                <span class="kwrd">do</span>
                {
                    size = s.Read(data, 0, data.Length);
                    streamWriter.Write(data, 0, size);
                } <span class="kwrd">while</span> (size &gt; 0);

                fileSize = Convert.ToDecimal(streamWriter.Length / 1024).ToString() + ” KB”;

                streamWriter.Close();

                <span class="rem">//Add custom code here to add each file to the DB, etc.</span>
            }
            <span class="kwrd">catch</span> (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }
    }

    s.Close();
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/03/how-to-unzip-files-in-net-using-sharpziplib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
