亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#使用WinRar命令進(jìn)行壓縮和解壓縮操作的實(shí)現(xiàn)方法

 更新時(shí)間:2016年06月09日 11:57:09   作者:smartsmile2012  
這篇文章主要介紹了C#使用WinRar命令進(jìn)行壓縮和解壓縮操作的實(shí)現(xiàn)方法,涉及C#基于Process類操作WinRar命令的相關(guān)實(shí)現(xiàn)技巧,代碼簡(jiǎn)潔實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了C#使用WinRar命令進(jìn)行壓縮和解壓縮操作的實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

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
    {
      //壓縮命令,相當(dāng)于在要壓縮的文件夾(path)上點(diǎn)右鍵->WinRAR->添加到壓縮文件->輸入壓縮文件名(rarName)
      string cmd = string.Format("a {0} {1} -r", rarName, path);
      startinfo.FileName = rarexe;
      startinfo.Arguments = cmd;             //設(shè)置命令參數(shù)
      startinfo.WindowStyle = ProcessWindowStyle.Hidden; //隱藏 WinRAR 窗口
      startinfo.WorkingDirectory = rarPath;
      process.StartInfo = startinfo;
      process.Start();
      process.WaitForExit(); //無(wú)限期等待進(jìn)程 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"; //文件解壓路徑(絕對(duì))
    string rarPath = @"C:\zip"; //將要解壓縮的 .rar 文件的存放目錄(絕對(duì)路徑)
    string rarexe = @"c:\Program Files\WinRAR\WinRAR.exe"; //WinRAR安裝位置
    try
    {
      //解壓縮命令,相當(dāng)于在要壓縮文件(rarName)上點(diǎn)右鍵->WinRAR->解壓到當(dāng)前文件夾
      string cmd = string.Format("x {0} {1} -y", rarName, path);
      startinfo.FileName = rarexe;
      startinfo.Arguments = cmd;             //設(shè)置命令參數(shù)
      startinfo.WindowStyle = ProcessWindowStyle.Hidden; //隱藏 WinRAR 窗口
      startinfo.WorkingDirectory = rarPath;
      process.StartInfo = startinfo;
      process.Start();
      process.WaitForExit(); //無(wú)限期等待進(jìn)程 winrar.exe 退出
      if (process.HasExited)
      {
        MSCL.JsHelper.Alert("解壓縮成功!", Page);
      }
    }
    catch (Exception ex)
    {
      MSCL.JsHelper.Alert(ex.Message, Page);
    }
    finally
    {
      process.Dispose();
      process.Close();
    }
  }
}

更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《C#常見(jiàn)控件用法教程》、《WinForm控件用法總結(jié)》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》及《C#程序設(shè)計(jì)之線程使用技巧總結(jié)

希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • C#最簡(jiǎn)單的關(guān)閉子窗體更新父窗體的實(shí)現(xiàn)方法

    C#最簡(jiǎn)單的關(guān)閉子窗體更新父窗體的實(shí)現(xiàn)方法

    原理就是將子窗體最為對(duì)話框模式彈出,當(dāng)窗體關(guān)閉或取消時(shí)更新主窗體
    2012-11-11
  • winform實(shí)現(xiàn)限制及解除鼠標(biāo)移動(dòng)范圍的方法

    winform實(shí)現(xiàn)限制及解除鼠標(biāo)移動(dòng)范圍的方法

    這篇文章主要介紹了winform實(shí)現(xiàn)限制及解除鼠標(biāo)移動(dòng)范圍的方法,涉及C#控制WinForm鼠標(biāo)事件屬性的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • C#操作INI文件的輔助類IniHelper

    C#操作INI文件的輔助類IniHelper

    這篇文章主要為大家詳細(xì)介紹了C#操作INI文件的輔助類IniHelper,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • C#實(shí)現(xiàn)集合轉(zhuǎn)換成json格式數(shù)據(jù)的方法

    C#實(shí)現(xiàn)集合轉(zhuǎn)換成json格式數(shù)據(jù)的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)集合轉(zhuǎn)換成json格式數(shù)據(jù)的方法,涉及C#針對(duì)dataTable、Enumerable及Json格式數(shù)據(jù)的遍歷及轉(zhuǎn)換操作相關(guān)技巧,需要的朋友可以參考下
    2016-07-07
  • C#使用Interlocked實(shí)現(xiàn)線程同步

    C#使用Interlocked實(shí)現(xiàn)線程同步

    今天小編就為大家分享一篇關(guān)于C#使用Interlocked實(shí)現(xiàn)線程同步,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2018-10-10
  • 如何在C#中使用指針

    如何在C#中使用指針

    這篇文章主要介紹了如何在C#中使用指針,文中代碼簡(jiǎn)單易懂,幫助大家更好的工作和學(xué)習(xí),感興趣的朋友快來(lái)了解下
    2020-06-06
  • 最新評(píng)論