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