我正在使用SharpZipLib解压缩文件。我的代码已经被很好地工作,除了为zip文件都zipfiles我现在所提取...SharpZipLib - ZipException“System.ArgumentOutOfRangeException” - 为什么我得到这个异常?
得到这个异常:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: length
异常正以size = s.Read(data, 0, data.Length);
抛出Hereb是我的代码...
public static void UnzipFile(string sourcePath, string targetDirectory)
{
try
{
using (ZipInputStream s = new ZipInputStream(File.OpenRead(sourcePath)))
{
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
//string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
if (targetDirectory.Length > 0)
{
Directory.CreateDirectory(targetDirectory);
}
if (fileName != String.Empty)
{
using (FileStream streamWriter = File.Create(targetDirectory + fileName))
{
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;
}
}
}
}
}
}
}
catch (Exception ex)
{
throw new Exception("Error unzipping file \"" + sourcePath + "\"", ex);
}
}
我刚刚试过你的例子,它对我的工作很好。 无论是zip包还是库版本问题。 我使用'v1.1.4322' – 2010-12-14 07:21:41
@Andrey:没有这样的SharpZipLib版本 - 最新版本是0.86。我认为你对.NET 1.1的更长版本号感到困惑。 – 2010-12-14 07:38:44
啊,对,它是运行时版本属性值。抱歉。 库的版本是0.84 – 2010-12-14 07:53:10