C#调用外部程序实现压缩和解压缩[原]
来源:互联网 发布:c语言md5加密函数 编辑:程序博客网 时间:2024/05/21 14:53
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using Microsoft.Win32;
- using System.Diagnostics;
- /*
- * 作者:Tom Hu
- * 日期:2008-10-10
- * BLOG:http://hi.baidu.com/huqing7002/blog
- *
- *
- * */
- namespace WebDisk
- {
- /// <summary>
- /// 压缩文件夹
- /// </summary>
- public class RarClass
- {
- public RarClass()
- {
- //
- // TODO: 在此处添加构造函数逻辑
- //
- }
- #region 压缩文件
- /// <summary>
- /// 压缩文件
- /// </summary>
- /// <param name="DFilePath">需要压缩的文件夹或者单个文件</param>
- /// <param name="DRARName">生成压缩文件的文件名</param>
- /// <param name="DRARPath">生成压缩文件保存路径</param>
- /// <returns></returns>
- public static bool RAR(string DFilePath, string DRARName, string DRARPath)
- {
- 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 " + " " + DRARName + " " + DFilePath; //命令 + 压缩后文件名 + 被压缩的文件或者路径
- the_StartInfo = new ProcessStartInfo();
- the_StartInfo.FileName = the_rar;
- the_StartInfo.Arguments = the_Info;
- the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
- the_StartInfo.WorkingDirectory = DRARPath; //RaR文件的存放目录。
- the_Process = new Process();
- the_Process.StartInfo = the_StartInfo;
- the_Process.Start();
- the_Process.WaitForExit();//让用户等待进程结束,我这里是要同时下载,否则可以不用写这句
- return true;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- #endregion
- #region 解压缩
- /// <summary>
- /// 解压缩到指定文件夹
- /// </summary>
- /// <param name="RARFilePath">压缩文件存在的目录 </param>
- /// <param name="RARFileName">压缩文件名称 </param>
- /// <param name="UnRARFilePath">解压到文件夹</param>
- /// <returns></returns>
- public static bool UnRAR(string RARFilePath, string RARFileName, string UnRARFilePath)
- {
- //解压缩
- 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 " + " " + RARFilePath + RARFileName + " " + UnRARFilePath;
- the_StartInfo = new ProcessStartInfo();
- the_StartInfo.FileName = the_rar;
- the_StartInfo.Arguments = the_Info;
- the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
- the_Process = new Process();
- the_Process.StartInfo = the_StartInfo;
- the_Process.Start();
- return true;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- #endregion
- }
- }
- C#调用外部程序实现压缩和解压缩[原]
- C#调用外部程序实现压缩和解压缩[原]
- C#调用外部程序实现压缩和解压缩[原]
- C#调用外部程序实现压缩和解压缩
- C#调用winrar进行压缩和解压缩
- C# 压缩和解压缩
- C#实现文件的压缩和解压缩
- C#实现文件的压缩和解压缩
- C#利用WinRAR实现压缩和解压缩
- c#调用7z压缩和解压缩文件
- .net2.0中,C#实现文件压缩和解压缩
- c# 实现zip格式文件的压缩和解压缩
- 调用Winrar.exe压缩和解压缩
- 调用Winrar.exe压缩和解压缩
- java和C#的压缩和解压缩
- C# 使用WinRar命令压缩和解压缩
- C# 使用WinRar命令压缩和解压缩
- asp实现在线压缩和解压缩
- 淘宝09和百度07年的一道编程题
- ASP+ACCESS动态创建表,添加修改删除字段
- flex 做的省市二级联动
- 35岁前做好十件事
- 姚博文 摒弃 spring
- C#调用外部程序实现压缩和解压缩[原]
- 公平的畅想
- Tomcat5.5的安装与配置
- CSS自适应宽度圆角按钮
- badi MUTI IMP
- Linux下的一些MySQL命令
- acts_as_nested_set的增强版BetterNestedSet
- 关于为什么不能在vc6.0中引入cpp文件
- 修改程序加入新功能