Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I want to unzip a file using C#, asp.net.

I dont want to use any third party tool.

Whenever I click on particular link (www.xxxxx.com/xxxxx.zip) it should automatically extract to a particular folder.

Thanks in advance
Posted
Updated 2-Sep-10 22:55pm
v3
Comments
Toli Cuturicu 2-Sep-10 15:09pm    
Removed spam.
Dalek Dave 3-Sep-10 4:55am    
Minor Edit for Grammar.

You may use SharpZipLib:
http://www.icsharpcode.net/OpenSource/SharpZipLib/[^]
Or, if you really do not want to use any external code, then you should write the compression / decompression algorithms yourself.
 
Share this answer
 
Please, take a look at namespace System.IO.Compression. It may be just what you are looking for.
 
Share this answer
 
You can download the whole source code for SharpZipLib from their site. Then open it in Visual Studio and study it!
 
Share this answer
 
this my class ,not use thrid party tool

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.IO.Compression;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;
using System.Xml;
using System.Text;


namespace My.Common
{
    public class function
    {
        public static MemoryStream CompressionStream(MemoryStream ms)
        {
            MemoryStream outStream = new MemoryStream();
            using (GZipStream output = new GZipStream(outStream, CompressionMode.Compress, true))
            {
                byte[] bytes = new byte[ms.Length];
                int n;
                while ((n = ms.Read(bytes, 0, bytes.Length)) != 0)
                {
                    output.Write(bytes, 0, n);
                }
            }
            outStream.Seek(0, SeekOrigin.Begin);
            return outStream;
        }
        public static MemoryStream DeCompressionStream(MemoryStream ms)
        {
            MemoryStream outStream = new MemoryStream();
            using (GZipStream input = new GZipStream(ms, CompressionMode.Decompress, true))
            {
                byte[] bytes = new byte[4096];
                int n;
                while ((n = input.Read(bytes, 0, bytes.Length)) != 0)
                {
                    outStream.Write(bytes, 0, n);
                }
            }
            outStream.Flush();
            outStream.Seek(0, SeekOrigin.Begin);
            return outStream;
        }
        public static Stream DeCompressionStream(Stream ms)
        {
            MemoryStream outStream = new MemoryStream();
            using (GZipStream input = new GZipStream(ms, CompressionMode.Decompress, true))
            {
                byte[] bytes = new byte[4096];
                int n;
                while ((n = input.Read(bytes, 0, bytes.Length)) != 0)
                {
                    outStream.Write(bytes, 0, n);
                }
            }
            outStream.Flush();
            outStream.Seek(0, SeekOrigin.Begin);
            return (Stream)outStream;
        } 

    }
}
 
Share this answer
 
Comments
Dalek Dave 3-Sep-10 4:55am    
Good Answer
You might wanna take a look at this thread:

http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/a343411d-f577-431b-92d7-5792912a7652[^]

Happy programming
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900