【问题标题】:Reduce file size with DotNetZip使用 DotNetZip 减小文件大小
【发布时间】:2013-09-18 04:43:32
【问题描述】:

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

            // 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 减小文件大小?

【问题讨论】:

    标签: c# asp.net compression smo dotnetzip


    【解决方案1】:

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

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

    您也可以参考以下链接获取详细答案 Compression issue with large archive of files in DotNetZip

    Pl。注意:库在压缩图像文件方面有限制,上面的链接将使您清楚地了解文件是否被压缩。您也可以参考 http://dotnetzip.herobo.com/DNZHelp/Index.html 获取有关此主题的更多帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-08
      • 2012-05-10
      • 2019-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-10
      • 1970-01-01
      相关资源
      最近更新 更多