国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#使用WinRar命令進行壓縮和解壓縮操作的實現方法

2020-01-24 01:07:04
字體:
來源:轉載
供稿:網友

本文實例講述了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#相關內容感興趣的讀者可查看本站專題:《C#常見控件用法教程》、《WinForm控件用法總結》、《C#數據結構與算法教程》、《C#面向對象程序設計入門教程》及《C#程序設計之線程使用技巧總結

希望本文所述對大家C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 得荣县| 夹江县| 尤溪县| 永春县| 清水河县| 平顶山市| 福安市| 高密市| 贡觉县| 涿州市| 介休市| 屯留县| 绥化市| 河北省| 措勤县| 炎陵县| 顺昌县| 博客| 项城市| 观塘区| 竹山县| 习水县| 和顺县| 杭锦后旗| 那曲县| 长阳| 昔阳县| 阿瓦提县| 苗栗市| 阿瓦提县| 大足县| 昌邑市| 阳高县| 宾川县| 平舆县| 夹江县| 临桂县| 仁寿县| 儋州市| 海南省| 连城县|