C#调用外部程序实现压缩和解压缩[原]
2008-10-10 10:08
701 查看
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
}
}
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#客户端程序调用外部程序的3种实现方法
- [转载]C#如何实现对外部程序的动态调用
- C#调用执行外部程序的实现方法
- C#实现对外部程序的调用操作
- C#实现对外部程序的调用操作
- C#程序实现动态调用DLL的研究
- C#程序实现动态调用DLL的研究(转载)
- 利用C#调用WINRAR实现压缩与解压
- QT编写DLL给外部程序调用,提供VC/C#/C调用示例(含事件)
- C#程序实现动态调用DLL的研究
- C#中利用process类调用外部程序以及执行dos命令
- 利用C#调用WINRAR实现压缩与解压
- C#程序调用外部程序
- C#调用外部程序
- [转]C#程序实现动态调用DLL的研究
- C#程序实现动态调用DLL的研究