//压缩
protected void btnY_Click(object sender, EventArgs e)
{
string rar;
RegistryKey reg;
string args;
ProcessStartInfo procStart;
Process process;
try
{
reg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
rar = reg.GetValue("").ToString();//获取注册表rar安装路径
reg.Close();
rar = rar.Substring(1, rar.Length - 7);//获取rar安装路径
args = "a -inul -y G:\\temp.rar G:\\1.txt";//这里为rar的压缩命令格式(也可以自行扩展)
procStart = new ProcessStartInfo();
procStart.FileName = rar;
procStart.Arguments = args;//参数
procStart.WindowStyle = ProcessWindowStyle.Hidden;//窗口状态
procStart.WorkingDirectory = Server.MapPath(""); ;//获取或设置要启动的进程的初始目录。
process = new Process();
process.StartInfo = procStart;
process.Start();
Response.Write("<script>alert('压缩成功')</script>");
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
//解压
protected void btnJ_Click(object sender, EventArgs e)
{
string rar;
RegistryKey reg;
string args;
ProcessStartInfo startInfo;
Process process;
try
{
reg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRar.exe\Shell\Open\Command");
rar = reg.GetValue("").ToString();
reg.Close();
rar = rar.Substring(1, rar.Length - 7);
args = " X E:\\temp.rar E:\\";
startInfo = new ProcessStartInfo();
startInfo.FileName = rar;
startInfo.Arguments = args;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
process = new Process();
process.StartInfo = startInfo;
process.Start();
Response.Write("<script>alert('解压成功')</script>");
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}