C#调用外部程序实现压缩和解压缩[原]
来源:互联网 发布:java document xml 编辑:程序博客网 时间:2024/05/17 07:35
- 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;
- 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实现在线压缩和解压缩
- 详细讲解:蓝屏代码的解答
- Adobe flash cs3 ActionScript 3.0入门
- .Net实用技巧
- 周杰伦的20句感人的歌词
- 国际商务英语学习[九]
- C#调用外部程序实现压缩和解压缩[原]
- 关于saveXML 和saveHTML的区别
- .net 关闭当前页面&amp;重定向&amp;get set
- 毕生精力总结的电脑技巧
- c# windows服务
- IT市场10大技术伟人 Linux之父居首
- 【send/sendto/sendmsg系统调用】
- struts2文件上传下载及乱码问题解决
- 为上司分忧而不单是分劳