我需要在保存文件之前检查文件是否被压缩。我创建了以下扩展方法来检查文件是否使用ZipFile
(来自SharpLibZip库)压缩:
public static bool IsCompressed(this HttpPostedFile postedFile)
{
Stream stream = postedFile.InputStream;
using (var zipFile = new ZipFile(stream))
{
return zipFile.TestArchive(true);
}
}
问题是当我调用HttpPostedFile.SaveAs()
它时将文件保存为 0kb:
if(uploadedFile.IsCompressed())
{
uploadedFile.InputStream.Seek(0, SeekOrigin.Begin);
uploadedFile.SaveAs(physicalZipFile.FullName);
}
这与在IsCompressed()
. 我曾尝试在保存之前从头开始,但问题仍然存在。
有人可以在这里解释这个问题吗?