欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

c#调用winrar解压缩文件代码分享

程序员文章站 2024-02-18 22:27:52
复制代码 代码如下:using microsoft.win32;using system.diagnostics;压缩string the_rar;registrykey...

复制代码 代码如下:

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>");
}