主要是使用Rar.exe壓縮解壓文件(夾)(*.rar),另外還有使用SevenZipSharp.dll、zLib1.dll、7z.dll壓縮解壓文件(夾)(*.zip)。需要注意的幾點如下:
1、注意Rar.exe軟件存放的位置,此次放在了Debug目錄下
2、SevenZipSharp.dll、zLib1.dll、7z.dll必須同時存在,否則常報“加載7z.dll錯誤”,項目引用時,只引用SevenZipSharp.dll即可
3、另外找不到7z.dll文件也會報錯,測試時發現只用@"..\..\dll\7z.dll";相對路徑時,路徑是變化的,故此處才用了string libPath = System.AppDomain.CurrentDomain.BaseDirectory + @"..\..\dll\7z.dll";
SevenZip.SevenZipCompressor.SetLibraryPath(libPath);
。
。
。
具體代碼如下:
Enums.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CompressProj { /// <summary> /// 執行壓縮命令結果 /// </summary> public enum CompressResults { Success, SourceObjectNotExist, UnKnown } /// <summary> /// 執行解壓縮命令結果 /// </summary> public enum UnCompressResults { Success, SourceObjectNotExist, PasswordError, UnKnown } /// <summary> /// 進程運行結果 /// </summary> public enum ProcessResults { Success, Failed } }
CommonFunctions.cs
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CompressProj { class CommonFunctions { #region 單例模式 private static CommonFunctions uniqueInstance; private static object _lock = new object(); private CommonFunctions() { } public static CommonFunctions getInstance() { if (null == uniqueInstance) //確認要實例化后再進行加鎖,降低加鎖的性能消耗。 { lock (_lock) { if (null == uniqueInstance) { uniqueInstance = new CommonFunctions(); } } } return uniqueInstance; } #endregion #region 進程 /// <summary> /// 另起一進程執行命令 /// </summary> /// <param name="exe">可執行程序(路徑+名)</param> /// <param name="commandInfo">執行命令</param> /// <param name="workingDir">執行所在初始目錄</param> /// <param name="processWindowStyle">進程窗口樣式</param> /// <param name="isUseShellExe">Shell啟動程序</param> public void ExecuteProcess(string exe, string commandInfo, string workingDir = "", ProcessWindowStyle processWindowStyle = ProcessWindowStyle.Hidden,bool isUseShellExe = false) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = exe; startInfo.Arguments = commandInfo; startInfo.WindowStyle = processWindowStyle; startInfo.UseShellExecute = isUseShellExe; if (!string.IsNullOrWhiteSpace(workingDir)) { startInfo.WorkingDirectory = workingDir; } ExecuteProcess(startInfo); } /// <summary> /// 直接另啟動一個進程 /// </summary> /// <param name="startInfo">啟動進程時使用的一組值</param> public void ExecuteProcess(ProcessStartInfo startInfo) { try { Process process = new Process(); process.StartInfo = startInfo; process.Start(); process.WaitForExit(); process.Close(); process.Dispose(); } catch(Exception ex) { throw new Exception("進程執行失敗:\n\r" + startInfo.FileName + "\n\r" + ex.Message); } } /// <summary> /// 去掉文件夾或文件的只讀屬性 /// </summary> /// <param name="objectPathName">文件夾或文件全路徑</param> public void Attribute2Normal(string objectPathName) { if (true == Directory.Exists(objectPathName)) { System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(objectPathName); directoryInfo.Attributes = FileAttributes.Normal; } else { File.SetAttributes(objectPathName,FileAttributes.Normal); } } #endregion } }
RarOperate.cs
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace CompressProj { class RarOperate { private CommonFunctions commFuncs = CommonFunctions.getInstance(); #region 單例模式 private static RarOperate uniqueInstance; private static object _lock = new object(); private RarOperate() { } public static RarOperate getInstance() { if (null == uniqueInstance) //確認要實例化后再進行加鎖,降低加鎖的性能消耗。 { lock (_lock) { if (null == uniqueInstance) { uniqueInstance = new RarOperate(); } } } return uniqueInstance; } #endregion #region 壓縮 /// <summary> /// 使用Rar.exe壓縮對象 /// </summary> /// <param name="rarRunPathName">Rar.exe路徑+對象名</param> /// <param name="objectPathName">被壓縮對象路徑+對象名</param> /// <param name="objectRarPathName">對象壓縮后路徑+對象名</param> /// <returns></returns> public CompressResults CompressObject(string rarRunPathName, string objectPathName, string objectRarPathName,string password) { try { //被壓縮對象是否存在 int beforeObjectNameIndex = objectPathName.LastIndexOf('\\'); string objectPath = objectPathName.Substring(0, beforeObjectNameIndex); //System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(objectPathName); if (Directory.Exists(objectPathName)/*directoryInfo.Exists*/ == false && System.IO.File.Exists(objectPathName) == false) { return CompressResults.SourceObjectNotExist; } //將對應字符串轉換為命令字符串 string rarCommand = "\"" + rarRunPathName + "\""; string objectPathNameCommand = "\"" + objectPathName + "\""; int beforeObjectRarNameIndex = objectRarPathName.LastIndexOf('\\'); int objectRarNameIndex = beforeObjectRarNameIndex + 1; string objectRarName = objectRarPathName.Substring(objectRarNameIndex); string rarNameCommand = "\"" + objectRarName + "\""; string objectRarPath = objectRarPathName.Substring(0, beforeObjectRarNameIndex); //目標目錄、文件是否存在 if (System.IO.Directory.Exists(objectRarPath) == false) { System.IO.Directory.CreateDirectory(objectRarPath); } else if (System.IO.File.Exists(objectRarPathName) == true) { System.IO.File.Delete(objectRarPathName); } //Rar壓縮命令 string commandInfo = "a " + rarNameCommand + " " + objectPathNameCommand + " -y -p" + password + " -ep1 -r -s- -rr "; //另起一線程執行 commFuncs.ExecuteProcess(rarCommand, commandInfo, objectRarPath, ProcessWindowStyle.Hidden); CompressRarTest(rarCommand, objectRarPathName, password); CorrectConfusedRar(objectRarPathName); } catch (Exception ex) { MessageBox.Show(ex.Message); return CompressResults.UnKnown; } return CompressResults.Success; } #endregion #region 解壓 /// <summary> /// 解壓:將文件解壓到某個文件夾中。 注意:要對路徑加上雙引號,避免帶空格的路徑,在rar命令中失效 /// </summary> /// <param name="rarRunPath">rar.exe的名稱及路徑</param> /// <param name="fromRarPath">被解壓的rar文件路徑</param> /// <param name="toRarPath">解壓后的文件存放路徑</param> /// <returns></returns> public UnCompressResults unCompressRAR(String rarRunPath, String objectRarPathName, String objectPath, string password) { try { bool isFileExist = File.Exists(objectRarPathName); if (false == isFileExist) { MessageBox.Show("解壓文件不存在!" + objectRarPathName); return UnCompressResults.SourceObjectNotExist; } File.SetAttributes(objectRarPathName, FileAttributes.Normal); //去掉只讀屬性 if (Directory.Exists(objectPath) == false) { Directory.CreateDirectory(objectPath); } String rarCommand = "\"" + rarRunPath + "\""; String objectPathCommand = "\"" + objectPath + "\\\""; String commandInfo = "x \"" + objectRarPathName + "\" " + objectPath + " -y -p" + password; commFuncs.ExecuteProcess(rarCommand, commandInfo, objectPath, ProcessWindowStyle.Hidden); MessageBox.Show("解壓縮成功!" + objectRarPathName); return UnCompressResults.Success; } catch { MessageBox.Show( "解壓縮失敗!" + objectRarPathName); return UnCompressResults.UnKnown; } } #endregion #region 進程 #endregion #region 測試壓縮文件 /// <summary> /// 測試壓縮后的文件是否正常。 /// </summary> /// <param name="rarRunPath"></param> /// <param name="rarFilePathName"></param> public bool CompressRarTest(String rarRunPath, String rarFilePathName,string password) { bool isOk = false; String commandInfo = "t -p" + password + " \"" + rarFilePathName + "\""; ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = rarRunPath; startInfo.Arguments = commandInfo; startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; startInfo.CreateNoWindow = true; Process process = new Process(); process.StartInfo = startInfo; process.Start(); StreamReader streamReader = process.StandardOutput; process.WaitForExit(); if (streamReader.ReadToEnd().ToLower().IndexOf("error") >= 0) { MessageBox.Show("壓縮文件已損壞!"); isOk = false; } else { MessageBox.Show("壓縮文件良好!"); isOk = true; } process.Close(); process.Dispose(); return isOk; } /// <summary> /// 混淆Rar /// </summary> /// <param name="objectRarPathName">rar路徑+名</param> /// <returns></returns> public bool ConfusedRar(string objectRarPathName) { try { //混淆 System.IO.FileStream fs = new FileStream(objectRarPathName, FileMode.Open); fs.WriteByte(0x53); fs.Close(); return true; } catch (Exception ex) { MessageBox.Show("混淆Rar失敗!" + ex.Message); return false; } } /// <summary> /// 糾正混淆的Rar /// </summary> /// <param name="objectRarPathName">rar路徑+名</param> /// <returns></returns> public bool CorrectConfusedRar(string objectRarPathName) { bool isCorrect = false; try { //先判斷一下待解壓文件是否經過混淆 FileStream fsRar = new FileStream(objectRarPathName, FileMode.Open, FileAccess.Read); int b = fsRar.ReadByte(); fsRar.Close(); if (b != 0x52) //R:0x52 原始開始值 { string strTempFile = System.IO.Path.GetTempFileName(); File.Copy(objectRarPathName, strTempFile, true); File.SetAttributes(strTempFile, FileAttributes.Normal); //去掉只讀屬性 FileStream fs = new FileStream(strTempFile, FileMode.Open); fs.WriteByte(0x52); fs.Close(); System.IO.File.Delete(objectRarPathName); File.Copy(strTempFile, objectRarPathName, true); } isCorrect = true; return isCorrect; } catch { MessageBox.Show("判斷待解壓文件是否經過混淆時出錯!" + objectRarPathName); return isCorrect; } } #endregion #region #endregion } }
ZipOperate.cs
using SevenZip;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CompressProj
{
class ZipOperate
{
#region 單例模式
private static ZipOperate uniqueInstance;
private static object _lock = new object();
private ZipOperate() { }
public static ZipOperate getInstance()
{
if (null == uniqueInstance) //確認要實例化后再進行加鎖,降低加鎖的性能消耗。
{
lock (_lock)
{
if (null == uniqueInstance)
{
uniqueInstance = new ZipOperate();
}
}
}
return uniqueInstance;
}
#endregion
#region 7zZip壓縮、解壓方法
/// <summary>
/// 壓縮文件
/// </summary>
/// <param name="objectPathName">壓縮對象(即可以是文件夾|也可以是文件)</param>
/// <param name="objectZipPathName">保存壓縮文件的路徑</param>
/// <param name="strPassword">加密碼</param>
/// 測試壓縮文件夾:壓縮文件(objectZipPathName)不能放在被壓縮文件(objectPathName)內,否則報“文件夾被另一進程使用中”錯誤。
/// <returns></returns>
public CompressResults Compress7zZip(String objectPathName, String objectZipPathName, String strPassword)
{
try
{
//http://sevenzipsharp.codeplex.com/releases/view/51254 下載sevenzipsharp.dll
//SevenZipSharp.dll、zLib1.dll、7z.dll必須同時存在,否則常報“加載7z.dll錯誤”
string libPath = System.AppDomain.CurrentDomain.BaseDirectory + @"..\..\dll\7z.dll";
SevenZip.SevenZipCompressor.SetLibraryPath(libPath);
SevenZip.SevenZipCompressor sevenZipCompressor = new SevenZip.SevenZipCompressor();
sevenZipCompressor.CompressionLevel = SevenZip.CompressionLevel.Fast;
sevenZipCompressor.ArchiveFormat = SevenZip.OutArchiveFormat.Zip;
//被壓縮對象是否存在
int beforeObjectNameIndex = objectPathName.LastIndexOf('\\');
string objectPath = objectPathName.Substring(0, beforeObjectNameIndex);
//System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(objectPathName);
if (Directory.Exists(objectPathName)/*directoryInfo.Exists*/ == false && System.IO.File.Exists(objectPathName) == false)
{
return CompressResults.SourceObjectNotExist;
}
int beforeObjectRarNameIndex = objectZipPathName.LastIndexOf('\\');
int objectRarNameIndex = beforeObjectRarNameIndex + 1;
//string objectZipName = objectZipPathName.Substring(objectRarNameIndex);
string objectZipPath = objectZipPathName.Substring(0, beforeObjectRarNameIndex);
//目標目錄、文件是否存在
if (System.IO.Directory.Exists(objectZipPath) == false)
{
System.IO.Directory.CreateDirectory(objectZipPath);
}
else if (System.IO.File.Exists(objectZipPathName) == true)
{
System.IO.File.Delete(objectZipPathName);
}
if (Directory.Exists(objectPathName)) //壓縮對象是文件夾
{
if (String.IsNullOrEmpty(strPassword))
{
sevenZipCompressor.CompressDirectory(objectPathName, objectZipPathName);
}
else
{
sevenZipCompressor.CompressDirectory(objectPathName, objectZipPathName, strPassword);
}
}
else //壓縮對象是文件 無加密方式
{
sevenZipCompressor.CompressFiles(objectZipPathName, objectPathName);
}
return CompressResults.Success;
}
catch(Exception ex)
{
MessageBox.Show("壓縮文件失敗!" + ex.Message);
return CompressResults.UnKnown;
}
}
/// <summary>
/// 解壓縮文件
/// </summary>
/// <param name="zipFilePathName">zip文件具體路徑+名</param>
/// <param name="unCompressDir">解壓路徑</param>
/// <param name="strPassword">解密碼</param>
/// <returns></returns>
public UnCompressResults UnCompress7zZip(String zipFilePathName, String unCompressDir, String strPassword)
{
try
{
//SevenZipSharp.dll、zLib1.dll、7z.dll必須同時存在,否則常報“加載7z.dll錯誤”而項目引用時,只引用SevenZipSharp.dll就可以了
string libPath = System.AppDomain.CurrentDomain.BaseDirectory + @"..\..\dll\7z.dll";
SevenZip.SevenZipCompressor.SetLibraryPath(libPath);
bool isFileExist = File.Exists(zipFilePathName);
if (false == isFileExist)
{
MessageBox.Show("解壓文件不存在!" + zipFilePathName);
return UnCompressResults.SourceObjectNotExist;
}
File.SetAttributes(zipFilePathName, FileAttributes.Normal); //去掉只讀屬性
if (Directory.Exists(unCompressDir) == false)
{
Directory.CreateDirectory(unCompressDir);
}
SevenZip.SevenZipExtractor sevenZipExtractor;
if (String.IsNullOrEmpty(strPassword))
{
sevenZipExtractor = new SevenZip.SevenZipExtractor(zipFilePathName);
}
else
{
sevenZipExtractor = new SevenZip.SevenZipExtractor(zipFilePathName, strPassword);
}
sevenZipExtractor.ExtractArchive(unCompressDir);
sevenZipExtractor.Dispose();
return UnCompressResults.Success;
}
catch(Exception ex)
{
MessageBox.Show("解壓縮文件失敗!" + ex.Message);
return UnCompressResults.UnKnown;
}
}
#endregion
}
}
FileOperate.cs
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace CompressProj { class FileOperate { private RarOperate rarOperate = RarOperate.getInstance(); #region 單例模式 private static FileOperate uniqueInstance; private static object _lock = new object(); private FileOperate() { } public static FileOperate getInstance() { if (null == uniqueInstance) //確認要實例化后再進行加鎖,降低加鎖的性能消耗。 { lock (_lock) { if (null == uniqueInstance) { uniqueInstance = new FileOperate(); } } } return uniqueInstance; } #endregion /// <summary> /// 打開文件 /// </summary> /// <param name="openFileDialog"></param> /// <param name="filter"></param> /// <param name="isReadOnly">是否另外開啟一使用該文件進程,防止該文件被操作</param> /// <returns></returns> public string OpenFile(OpenFileDialog openFileDialog,string filter,string openFileDialogTitle = "壓縮文件",bool isReadOnly = false) { string filePathName = string.Empty; if (string.IsNullOrEmpty(filter)) { filter = "AllFiles(*.*)|*.*"; //TXT(*.txt)|*.txt|Word(*.doc,*.docx)|*.doc;*.docx|圖像文件(*.gif;*.jpg;*.jpeg;*.png;*.psd)|*.gif;*.jpg;*.jpeg;*.png;*.psd| } openFileDialog.Filter = filter; DialogResult dResult = openFileDialog.ShowDialog(); if (dResult == DialogResult.OK) { string defaultExt = ".docx"; //string filter = string.Empty; //openFileDialog.ReadOnlyChecked = isReadOnly; openFileDialog.SupportMultiDottedExtensions = true; openFileDialog.AutoUpgradeEnabled = true; openFileDialog.AddExtension = true; openFileDialog.CheckPathExists = true; openFileDialog.CheckFileExists = true; openFileDialog.DefaultExt = defaultExt; openFileDialog.Multiselect = true; openFileDialog.ShowReadOnly = true; openFileDialog.Title = openFileDialogTitle; openFileDialog.ValidateNames = true; openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Templates); //添加后界面沒變化 Win7 + VS11 openFileDialog.ShowHelp = true; filePathName = openFileDialog.FileName; if (true == isReadOnly) { openFileDialog.OpenFile(); //打開只讀文件,即開啟一使用該文件進程,防止其他進程操作該文件 } openFileDialog.Dispose(); } return filePathName; } /// <summary> /// 打開文件 /// </summary> /// <param name="saveFileDialog"></param> /// <param name="filter"></param> /// <param name="isReadOnly"></param> /// <returns></returns> public string SaveFile(SaveFileDialog saveFileDialog, string filter,string saveFileDialogTitle = "保存文件", bool isReadOnly = false) { string filePathName = string.Empty; if (string.IsNullOrEmpty(filter)) { filter = "AllFiles(*.*)|*.*"; //TXT(*.txt)|*.txt|Word(*.doc,*.docx)|*.doc;*.docx|圖像文件(*.gif;*.jpg;*.jpeg;*.png;*.psd)|*.gif;*.jpg;*.jpeg;*.png;*.psd| } saveFileDialog.Filter = filter; DialogResult dResult = saveFileDialog.ShowDialog(); if (dResult == DialogResult.OK) { string defaultExt = ".docx"; //string filter = string.Empty; //string saveFileDialogTitle = "保存文件"; saveFileDialog.SupportMultiDottedExtensions = true; saveFileDialog.AutoUpgradeEnabled = true; saveFileDialog.AddExtension = true; saveFileDialog.CheckPathExists = true; saveFileDialog.CheckFileExists = true; saveFileDialog.DefaultExt = defaultExt; saveFileDialog.RestoreDirectory = true; saveFileDialog.OverwritePrompt = true; saveFileDialog.Title = saveFileDialogTitle; saveFileDialog.ValidateNames = true; saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Templates); //添加后界面沒變化 Win7 + VS11 saveFileDialog.ShowHelp = true; filePathName = saveFileDialog.FileName; if (true == isReadOnly) { saveFileDialog.OpenFile(); //打開只讀文件,即開啟一使用該文件進程,防止其他進程操作該文件 } saveFileDialog.Dispose(); } return filePathName; } } }
測試調用代碼如下:
RarForm.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace CompressProj { public partial class RarForm : Form { private FileOperate fileOperate = FileOperate.getInstance(); private RarOperate rarOperate = RarOperate.getInstance(); private ZipOperate zipOperate = ZipOperate.getInstance(); public RarForm() { InitializeComponent(); } private void btnCompress_Click(object sender, EventArgs e) { string filter = "TXT(*.txt)|*.txt|Word(*.doc,*.docx)|*.doc;*.docx|AllFiles(*.*)|*.*"; string openFileDialogTitle = "壓縮文件"; string compressFilePathName = fileOperate.OpenFile(this.openFileDialog1, filter, openFileDialogTitle,true); if (string.IsNullOrEmpty(compressFilePathName) || string.IsNullOrWhiteSpace(compressFilePathName)) { return; } this.openFileDialog1.HelpRequest += new EventHandler(openFileDialog1_HelpRequest); string objectRarPathName = compressFilePathName.Substring(0,compressFilePathName.LastIndexOf('.')) + ".rar"; string rarPathName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Rar.exe"; string password = string.Empty;//"shenc"; CompressResults compressResult = rarOperate.CompressObject(rarPathName, compressFilePathName, objectRarPathName, password); if (CompressResults.Success == compressResult) { MessageBox.Show(objectRarPathName); } } private void openFileDialog1_HelpRequest(object sender, EventArgs e) { MessageBox.Show("HelpRequest!"); } private void btnUncompress_Click(object sender, EventArgs e) { string filter = "Rar(*.rar)|*.rar"; string openFileDialogTitle = "解壓文件"; string unCompressFilePathName = fileOperate.OpenFile(this.openFileDialog1, filter, openFileDialogTitle, false); if (string.IsNullOrEmpty(unCompressFilePathName) || string.IsNullOrWhiteSpace(unCompressFilePathName)) { return; } string objectPath = unCompressFilePathName.Substring(0, unCompressFilePathName.LastIndexOf('.')); string rarPathName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Rar.exe"; string password = string.Empty;//"shenc"; UnCompressResults unCompressResult = rarOperate.unCompressRAR(rarPathName, unCompressFilePathName, objectPath, password); if (UnCompressResults.Success == unCompressResult) { MessageBox.Show(objectPath); } } private void btnCompressZip_Click(object sender, EventArgs e) { string filter = "TXT(*.txt)|*.txt|Word(*.doc,*.docx)|*.doc;*.docx|AllFiles(*.*)|*.*"; string openFileDialogTitle = "壓縮文件"; string compressFilePathName = fileOperate.OpenFile(this.openFileDialog1, filter, openFileDialogTitle, false); if (string.IsNullOrEmpty(compressFilePathName) || string.IsNullOrWhiteSpace(compressFilePathName)) { return; } //this.openFileDialog1.HelpRequest += new EventHandler(openFileDialog1_HelpRequest); string password = string.Empty;//"shenc"; string objectZipPathName = compressFilePathName.Substring(0, compressFilePathName.LastIndexOf('.')) + ".zip"; CompressResults compressResult = zipOperate.Compress7zZip(compressFilePathName, objectZipPathName, password); //壓縮文件 ////測試壓縮文件夾:壓縮文件不能放在被壓縮文件內,否則報“文件夾被另一進程使用中”錯誤。 //string objectPath = compressFilePathName.Substring(0, compressFilePathName.LastIndexOf('\\')); //objectZipPathName = objectPath + ".zip"; //CompressResults compressResult = zipOperate.Compress7zZip(objectPath, objectZipPathName, password); //壓縮文件夾 if (CompressResults.Success == compressResult) { MessageBox.Show(objectZipPathName); } } private void btnUnCompressZip_Click(object sender, EventArgs e) { string filter = "Zip(*.zip)|*.zip"; string openFileDialogTitle = "解壓文件"; string unCompressFilePathName = fileOperate.OpenFile(this.openFileDialog1, filter, openFileDialogTitle, false); if (string.IsNullOrEmpty(unCompressFilePathName) || string.IsNullOrWhiteSpace(unCompressFilePathName)) { return; } string objectPath = unCompressFilePathName.Substring(0, unCompressFilePathName.LastIndexOf('.')); string password = string.Empty;//"shenc"; UnCompressResults unCompressResult = zipOperate.UnCompress7zZip(unCompressFilePathName, objectPath, password); if (UnCompressResults.Success == unCompressResult) { MessageBox.Show(objectPath); } } } }
