2

我想知道是否可以在不使用 .net 4.0 或更低版本中的开源 dll 的情况下以 c sharp 解压缩文件?

我有一些使用“Shell”命令的 VBA 代码(如下)。升c也可以吗?

Sub UnzipMe(path)

Dim strDOSCMD As String
Dim filename As String
Dim i As Integer


filename = path + "\test.txt"
strDOSCMD = "unzip -n " + path + "\zipfile.zip -d " + path
'SEND TO DOS
retval = Shell(strDOSCMD, vbHide)


End Sub

这很好用而且非常简单,但我想用 c Sharp 完成这一切,而不是混合搭配。当然这应该是可行的,或者应该有一个同样简单的解决方案?

4

1 回答 1

1

您可以在 C# 中使用Process.Start.

您的代码可能看起来像(未经测试..):

public void UnzipMe(string path){
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = "cmd.exe";
    startInfo.Arguments = "/C unzip -n " + path + "\zipfile.zip -d " + path;
    process.StartInfo = startInfo;
    process.Start();
    //do some extra stuff here
}

对于 zip 的东西,考虑使用第三方库,就像sharpziplib我在许多项目中成功使用它一样。

看看这些样本:https ://github.com/icharpcode/SharpZipLib/wiki/Zip-Samples

于 2013-07-23T10:52:26.073 回答