首先加入命名空間
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());
}