【摘錄】Asp.net實現在線壓縮與解壓

來源:互聯網
上載者:User

首先加入命名空間

using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Diagnostics;

實現壓縮方法:

{
function anonymous()
{
function anonymous()
{
function onclick()
{
this.style.display='none'; document.getElementById('Code_Closed_Text_180905').style.display='none'; document.getElementById('Code_Open_Image_180905').style.display='inline'; document.getElementById('Code_Open_Text_180905').style.display='inline';
}
}
}
}" style="display: none;" id="Code_Closed_Image_180905">{
function anonymous()
{
function anonymous()
{
function onclick()
{
this.style.display='none'; document.getElementById('Code_Open_Text_180905').style.display='none'; getElementById('Code_Closed_Image_180905').style.display='inline'; getElementById('Code_Closed_Text_180905').style.display='inline';
}
}
}
}" id="Code_Open_Image_180905">
//壓縮
        String strRar;
        RegistryKey rkReg;
        Object obj;
        String strInfo;
        ProcessStartInfo psiInfo;
        Process pProcess;
        try
        {
            rkReg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
            obj = rkReg.GetValue("");
            strRar = obj.ToString();
            rkReg.Close();
            strRar = strRar.Substring(1, strRar.Length - 7);
            strInfo = "a  -r  -ep1 test.rar " + lblTree.Text + @"rar/test1.txt " + lblTree.Text + @"rar";//這裡為rar的壓縮命令格式(也可以自行擴充)
            psiInfo = new ProcessStartInfo();
            psiInfo.FileName = strRar;
            psiInfo.Arguments = strInfo;
            psiInfo.WindowStyle = ProcessWindowStyle.Hidden;
            psiInfo.WorkingDirectory = lblTree.Text + "rar"; ;//擷取或設定要啟動的進程的初始目錄。
            pProcess = new Process();
            pProcess.StartInfo = psiInfo;
            pProcess.Start();
            Response.Write("<font color=red>壓縮成功</font>");
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }

實現解壓方法:

//解壓縮
        String strRar;
        RegistryKey rkReg;
        Object obj;
        String strInfo;
        ProcessStartInfo psiInfo;
        Process pProcess;
        try
        {
            rkReg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRar.exe\Shell\Open\Command");
            obj = rkReg.GetValue("");
            strRar = obj.ToString();
            rkReg.Close();
            strRar = strRar.Substring(1, strRar.Length - 7);
            strInfo = " X " + lblTree.Text + @"rar/test.rar " + " " + lblTree.Text + @"unRar";
            psiInfo = new ProcessStartInfo();
            psiInfo.FileName = strRar;
            psiInfo.Arguments = strInfo;
            psiInfo.WindowStyle = ProcessWindowStyle.Hidden;
            pProcess = new Process();
            pProcess.StartInfo = psiInfo;
            pProcess.Start();
            Response.Write("<font color=red>解壓縮成功</font>");
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.