使用DotNetZip减小文件大小 [英] Reduce file size with DotNetZip

查看:135
本文介绍了使用DotNetZip减小文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用SMO备份数据库并压缩一个备份文件,然后将其上传到我的服务器。这是我的代码

I want to backup my database using SMO and zip a backup file then upload it to my server. here is my code

            // Backup
            var conn = new SqlConnection(sqlConnectionString);
            var server = new Server(new ServerConnection(conn));
            var backupMgr = new Backup();
            backupMgr.Devices.AddDevice(file.FullName, DeviceType.File);
            backupMgr.Database = dictionary[StringKeys.Database];
            backupMgr.Action = BackupActionType.Database;
            backupMgr.SqlBackup(server);

            // Compress
            using (var zip = new ZipFile())
            {
                zipFile = string.Format("{0}\\{1}.zip", directoryName, DateTime.Now.ToString("yyyyMMddHHmm"));
                zip.AddFile(outputPath, "");

                zip.Save(zipFile);
            }

            // uploading code

备份大小文件可以超过100MB。但是,使用上面的代码将其压缩后,它并不会减小大小。
所以我不能上传较大的zip文件。是否可以使用DotNetZip减小文件大小?

Size of a backup file can be more than 100MB. But after i zip this using above code, it doesn't reduce the size. So I cannot upload larger zip files. Is there way to reduce the file size with DotNetZip?

推荐答案

您可以通过在保存之前添加以下行来做到这一点

you can do that by adding the following line before save

zip.CompressionLevel= Ionic.Zlib.CompressionLevel.BestCompression;

或者,您可以参考以下链接以获得详细答案
DotNetZip中的大型文件存档存在压缩问题

Alternatively you can refer to following link for detailed answer Compression issue with large archive of files in DotNetZip

Pl。注意:该库在压缩图像文件方面有局限性,上面的链接将使您清楚地了解文件是否正在压缩。您还可以引用 http://dotnetzip.herobo.com/DNZHelp/Index.html有关此主题的其他帮助

Pl. Note: the Library has limitations in compressing image files, the above link will give you a clear understanding of whether the file is getting compressed or not. You can also refer http://dotnetzip.herobo.com/DNZHelp/Index.html for additional help on this topic

这篇关于使用DotNetZip减小文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆