In the actual project application will occasionally use the file compression upload and server-side pressure processing, so write this document for a rainy time.
1. Write your own Ziphelper class.
1 Public Static classZiphelper2 {3 Private Static stringPathexe = AppDomain.CurrentDomain.BaseDirectory +@"Resource\winrar.exe";4 /// <summary>5 ///compressing files using the Gzip method6 /// </summary>7 /// <param name= "sourceFileName" ></param>8 /// <param name= "Zipfilename" ></param>9 /// <returns></returns>Ten Public Static BOOLGzipfile (stringsourceFileName,stringzipfilename) One { A BOOLISSUCC =false; - //stitching Compression Command Parameters - stringargs =string. Format ("a-as-r-afzip-ed-ibck-inul-m5-mt5-ep1 {0} {1}", Zipfilename, sourceFileName); the - //start the compression process -ISSUCC =processhelper.startprocess (Pathexe,args); - returnISSUCC; + } - + /// <summary> A ///How to extract files using gzip at /// </summary> - /// <param name= "Zipfilename" ></param> - /// <param name= "Unzipfilename" ></param> - /// <returns></returns> - Public Static BOOLUngzipfile (stringZipfilename,stringunzipfilename) - { in BOOLISSUCC =false; - if(!directory.exists (unzipfilename)) to { + directory.createdirectory (unzipfilename); - } the //Stitching Decompression Command Parameters * stringargs =string. Format ("x-ibck-inul-y-mt5 {0} {1}", Zipfilename, unzipfilename); $ Panax Notoginseng //start the decompression process -ISSUCC =processhelper.startprocess (Pathexe, args); the returnISSUCC; + } A}
2. The Processhelper class used.
1 Public classProcesshelper2 {3 /// <summary>4 ///START Process Execution exe5 /// </summary>6 /// <param name= "ExePath" >exe path</param>7 /// <param name= "Exeargs" >exe Required Parameters</param>8 /// <returns></returns>9 Public Static BOOLStartProcess (stringExePath,stringExeargs)Ten { One BOOLIshidden =true; A BOOLISSUCC =true; -Process Process =NewProcess (); -Process. Startinfo.filename =ExePath; theProcess. Startinfo.arguments =Exeargs; - if(Ishidden) - { -Process. Startinfo.windowstyle =Processwindowstyle.hidden; +Process. Startinfo.createnowindow =true; - } + Else A { atProcess. Startinfo.windowstyle =Processwindowstyle.normal; -Process. Startinfo.createnowindow =false; - } - process. Start (); - intIDX =1; - while(!process. hasexited) in { -idx++; toProcess. WaitForExit ( +); + if(idx = = -) - { the process. Kill (); *ISSUCC =false; $ }Panax Notoginseng } - process. Close (); the process. Dispose (); + returnISSUCC; A } the}
3.WinRar Related commands explained:
/* * < command >-< switch 1>-< switch n> < compress file > < file. .. > <@ list file ...> < unzip path \> * compression a a-as- R-afzip-ed-ibck-inul-m5-mt5-ep1 e:\text.zip d:\text.jpg * extract x &NBSP;X-IBCK-INUL-Y-mt5 e:\text.zip e:\text *a D:\Info.zip d:\easyui &NBSP;*-AF specify format-afzip-afrar & nbsp *-as compressed files that do not exist in the list of currently added files will be deleted from the compressed file &NBSP;*-DF Compressed Delete the source files and nbsp; &NBSP;*-DR Delete to Recycle Bin *-ed Do not add empty folders &NBSP;*-HP add password-hp123456 After &NBSP;*-IBCKOperation *-inul suppress error messages &NBS P;*-loff after compression is complete, turn off power &NBSP;*-M0 store add files to compressed files but do not compress &NBSP;*-M1 fastest and fastest method (lowest compression ratio) &NBSP;*-M2 quick and fast Fast compression methods &NBSP;*-M3 Standard (Default) compression method &NBSP;*-M4 Better compression method (higher compression ratio) &NBSP;*-M5 optimal compression method (maximum compression ratio but slowest speed) ) &NBSP;*-MTN thread-mt5 1~32 & Nbsp;*-or automatically rename files *-r together with sub-files & nbsp *-z compression test file *-y all pop-up windows Select "Yes" &NBS P */ 4. Official-related decompression command-line explanation: 5. Using the method, copy the WinRar.exe to your project's specified directory to call directly.