using ICSharpCode.SharpZipLib.Zip;
using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
namespace DataReportedFeedBack
{
public class UnZipClass
{
public void UnZip(string[] args)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(args[1]);
string fileName = Path.GetFileName(theEntry.Name);
//生成解压目录
// create directory
if (directoryName != "")
{
Directory.CreateDirectory(directoryName);
}
if (fileName != String.Empty)
{
//if (theEntry.Name.IndexOf(".ini") < 0)
//{
string fullPath = directoryName + "//" + theEntry.Name;
fullPath = fullPath.Replace("// ", "//");
string fullDirPath = Path.GetDirectoryName(fullPath);
if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
FileStream streamWriter = File.Create(fullPath);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
//}
}
}
s.Close();
}
}
}
调用:
private void button3_Click(object sender, EventArgs e)
{
string[] FileProperties = new string[2];
待解压的文件
FileProperties[0] = strToBak1Directory + "//" + f.Name;
解压后放置的目标目录
FileProperties[1] = strTempDiretory+"//";
UnZipClass UnZc = new UnZipClass();
UnZc.UnZip(FileProperties);
}