c#调用winrar解压缩文件代码分享
using microsoft.win32;
using system.diagnostics;
压缩
string the_rar;
registrykey the_reg;
object the_obj;
string the_info;
processstartinfo the_startinfo;
process the_process;
try
{
the_reg = registry.classesroot.opensubkey(@"applications\winrar.exe\shell\open\command");
the_obj = the_reg.getvalue("");
the_rar = the_obj.tostring();
the_reg.close();
the_rar = the_rar.substring(1, the_rar.length - 7);
the_info = " a " + " test.rar " + " " + @"c:\test\test.txt";
the_startinfo = new processstartinfo();
the_startinfo.filename = the_rar;
the_startinfo.arguments = the_info;
the_startinfo.windowstyle = processwindowstyle.hidden;
the_startinfo.workingdirectory = @"c:\test\";
the_process = new process();
the_process.startinfo = the_startinfo;
the_process.start();
response.write("<script>alert('zip successfully');</script>");
}
catch
{
response.write("<script>alert('zip failed.')</script>");
}
解压缩
string the_rar;
registrykey the_reg;
object the_obj;
string the_info;
processstartinfo the_startinfo;
process the_process;
try
{
the_reg = registry.classesroot.opensubkey(@"applications\winrar.exe\shell\open\command");
the_obj = the_reg.getvalue("");
the_rar = the_obj.tostring();
the_reg.close();
the_rar = the_rar.substring(1, the_rar.length - 7);
the_info = " x " + " test.rar " + @"c:\test\";
the_startinfo = new processstartinfo();
the_startinfo.filename = the_rar;
the_startinfo.arguments = the_info;
the_startinfo.windowstyle = processwindowstyle.hidden;
the_startinfo.workingdirectory = @"c:\test\";
the_process = new process();
the_process.startinfo = the_startinfo;
the_process.start();
response.write("<script>alert('unzip successfully');</script>");
}
catch
{
response.write("<script>alert('unzip failed.')</script>");
}