Example of extracting files using DotNetZip in asp.net C #

Source: Internet
Author: User

DotNetZip Download Address: http://dotnetzip.codeplex.com/

Compression:

  code is as follows copy code

//define File path
string filename = @ "D:/test.rar";
 
using (zipfile zip = new ZipFile ())
 
{
    zip. AddFile (@ "c:/text.txt", "txt");//store text files in txt folder
    zip. AddFile (@ "C:/readme.txt");//The ReadMe file is stored in a more directory
    zip. AddFile (@ "c:/test.jpg", "Images");//store test file in Images folder
}

Extract:


using (zipfile zip = new Zipfi Le (filename)
{
    zip. Extractall ("D:\\test", extractexistingfileaction.overwritesilently);
}

  code is as follows copy code


/////// Replace the content
String str2 = System.Text.Encoding.GetEncoding ("GB2312"). GetString (buf, start, maxlength);
return str2;

////////////////////////replaced content
//int i;
//char[] C = new Char[maxlength];
//for (i = 0; (I < maxlength) && (i < buf.) Length) && (Buf[i]!= 0); i++)
//{
//    c[i] = (char) buf[i];//System.BitConverter.ToChar (BUF, start+i*2);
//}
// string s = new System.String (c, 0, I);
//return S;
////////////////////////

This method to the effect is that the byte array into a character array, the encoding of Chinese characters into two characters, which obviously will result in garbled, since the encoding using GetBytes, then the decoding is used to reverse, getstring on the line, compile run, finished

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.