C#應用WinRar敕令停止緊縮息爭緊縮操作的完成辦法。本站提示廣大學習愛好者:(C#應用WinRar敕令停止緊縮息爭緊縮操作的完成辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#應用WinRar敕令停止緊縮息爭緊縮操作的完成辦法正文
本文實例講述了C#應用WinRar敕令停止緊縮息爭緊縮操作的完成辦法。分享給年夜家供年夜家參考,詳細以下:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Diagnostics; using System.IO; public partial class Zip : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } //緊縮文件 protected void Button1_Click(object sender, EventArgs e) { ProcessStartInfo startinfo = new ProcessStartInfo(); ; Process process = new Process(); string rarName = "1.rar"; //緊縮後文件名 string path = @"C:\images"; //待緊縮打包文件夾 string rarPath = @"C:\zip"; //緊縮後寄存文件夾 string rarexe = @"c:\Program Files\WinRAR\WinRAR.exe"; //WinRAR裝置地位 try { //緊縮敕令,相當於在要緊縮的文件夾(path)上點右鍵->WinRAR->添加到緊縮文件->輸出緊縮文件名(rarName) string cmd = string.Format("a {0} {1} -r", rarName, path); startinfo.FileName = rarexe; startinfo.Arguments = cmd; //設置敕令參數 startinfo.WindowStyle = ProcessWindowStyle.Hidden; //隱蔽 WinRAR 窗口 startinfo.WorkingDirectory = rarPath; process.StartInfo = startinfo; process.Start(); process.WaitForExit(); //無窮期期待過程 winrar.exe 加入 if (process.HasExited) { MSCL.JsHelper.Alert("緊縮勝利!", Page); } } catch (Exception ex) { MSCL.JsHelper.Alert(ex.Message, Page); } finally { process.Dispose(); process.Close(); } } //解壓文件 protected void Button2_Click(object sender, EventArgs e) { ProcessStartInfo startinfo = new ProcessStartInfo(); ; Process process = new Process(); string rarName = "1.rar"; //將要解緊縮的 .rar 文件名(包含後綴) string path = @"C:\images1"; //文件解壓途徑(相對) string rarPath = @"C:\zip"; //將要解緊縮的 .rar 文件的寄存目次(相對途徑) string rarexe = @"c:\Program Files\WinRAR\WinRAR.exe"; //WinRAR裝置地位 try { //解緊縮敕令,相當於在要緊縮文件(rarName)上點右鍵->WinRAR->解壓到以後文件夾 string cmd = string.Format("x {0} {1} -y", rarName, path); startinfo.FileName = rarexe; startinfo.Arguments = cmd; //設置敕令參數 startinfo.WindowStyle = ProcessWindowStyle.Hidden; //隱蔽 WinRAR 窗口 startinfo.WorkingDirectory = rarPath; process.StartInfo = startinfo; process.Start(); process.WaitForExit(); //無窮期期待過程 winrar.exe 加入 if (process.HasExited) { MSCL.JsHelper.Alert("解緊縮勝利!", Page); } } catch (Exception ex) { MSCL.JsHelper.Alert(ex.Message, Page); } finally { process.Dispose(); process.Close(); } } }
願望本文所述對年夜家C#法式設計有所贊助。