写一个从EXCEL里面读取照片路径
///
/// 解压文件
///
/// <param name="zipFilePath">压缩文件路径</param>
/// <param name="path">返回压缩文件夹路径</param>
/// <param name="unZipDir">解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹</param>
/// <returns></returns>
private bool UnZipFile(string zipFilePath, out string path, string unZipDir = null)
{
if (zipFilePath == string.Empty)
{
path = null;
return false;
}
if (!System.IO.File.Exists(zipFilePath))
{
path = null;
return false;
}
//解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹
if (string.IsNullOrWhiteSpace(unZipDir))
unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath));
if (!unZipDir.EndsWith("\\"))
unZipDir += "\\";
if (!Directory.Exists(unZipDir))
Directory.CreateDirectory(unZipDir);
try
{
using (ZipInputStream s = new ZipInputStream(System.IO.File.OpenRead(zipFilePath)))
{
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
if (directoryName.Length > 0)
{
Directory.CreateDirectory(unZipDir + directoryName);
}
if (!directoryName.EndsWith("\\"))
directoryName += "\\";
if (fileName != String.Empty)
{
using (FileStream streamWriter = System.IO.File.Create(unZipDir + theEntry.Name))
{
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
{
path = null;
return false;
}
path = unZipDir;
return true;
}
}
在 while ((theEntry = s.GetNextEntry()) != null)的地方 s.GetNextEntry()) 会抛出 Unexpected EOF
有没有遇到过这个问题的可以分享一下解决方案