1

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

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?

4

1 回答 1

3

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

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

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

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

于 2013-09-18T05:12:33.850 回答