[英]Create and download zip file in c#
在我的C#应用程序中,我试图根据从用户那里获得的附件创建一个zip文件,然后下载该zip文件。 首先,我尝试使用SharpZipLib,但是没有用。
我收到以下错误:
线程中止错误。
现在我正在尝试使用
System.IO.Compression;
但那里有些问题,因为我收到此错误:
The type or namespace name 'ZipFile' could not be found (are you missing a using directive or an assembly reference?)
我现在尝试添加dll参考
using (ZipFile zip = new ZipFile())
{
zip.CompressionLevel = CompressionLevel.Fastest;
zip.AddSelectedFiles(logoimage, "", false);
zip.Save(HttpContext.Current.Response.OutputStream);
}
我得到这个错误,
Cannot declare a variable of static type 'System.IO.Compression.ZipFile'
有什么想法吗?
如错误所示, System.IO.Compression.ZipFile
是静态类,因此您无法创建一个new
实例。
ZipFile
类仅公开静态方法来压缩目录,以压缩要使用System.IO.Compression.ZipArchive
的特定文件。
使用System.Io.Compression
,可以使用GZipStream类压缩和解压缩流。
如此处所述,要使用ZipFile类,必须在项目中添加对System.IO.Compression.FileSystem
程序集的引用。 否则,在尝试编译时会出现以下错误消息: The name 'ZipFile' does not exist in the current context
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.