当前位置: 移动技术网 > IT编程>开发语言>c# > c#调用winrar解压缩文件代码分享

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

2019年07月18日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下: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>");
}

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网