Go C # How to Package folder compression and download

Source: Internet
Author: User

 Public Partial class_default2:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) {            }          protected voidButton1_Click (Objectsender, EventArgs e) {              stringPath ="C:\\de"; stringResultpath =string.              Empty; BOOLrel =false; TimeSpan Nowtimespan=NewTimeSpan (); Resultpath=yasuo ( outRel outNowtimespan);          Responsefile (Resultpath); }            /// <summary>          ///Compress Files/// </summary>          /// <returns>returns the compressed path</returns>           Public stringYaSuo ( out BOOLBo outTimeSpan Times) {              stringRarurlpath =string.              Empty; Bo=false; //Compress Files            stringYasuopathsave ="C:\\de\\tz.rar"; stringYasuopath ="c:\\de\\temp"; System.Diagnostics.Process Pro=NewSystem.Diagnostics.Process (); Pro. Startinfo.filename=@"C:\Program Files\winrar\winrar.exe";//The path where the WinRAR//Pro. Startinfo.arguments = "a" + Yasuopathsave + "" + Yasuopath + "-r";//dir is your directory namePro. Startinfo.arguments =string. Format ("a {0} {1}-R", Yasuopathsave,yasuopath); Pro.              Start (); Times=Pro.              Totalprocessortime; Bo= Pro. WaitForExit (60000);//set a minute            if(!bo) Pro.              Kill (); Pro.              Close (); Pro.              Dispose (); Rarurlpath=Yasuopathsave; returnRarurlpath; }              protected voidResponsefile (stringfilename) {FileInfo file=NewFileInfo (filename);//Create a File objectResponse.Clear ();//clear the contents of all buffersResponse.Charset ="GB2312";//defining the output character setresponse.contentencoding = Encoding.default;//the encoding of the output content is the default encodingResponse.AddHeader ("content-disposition","attachment;filename="+file.              Name); //Add header information. Specify the default file name for file download/Save asResponse.AddHeader ("Content-length", file.              Length.tostring ()); //Add header file, specify the size of the file, let the browser show the speed of file downloadResponse.WriteFile (file. FullName);//send the file stream to the clientResponse.End (); }          }  

Go C # How to Package folder compression and download

Related Article

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.