Reduce file size with DotNetZip

ぃ、小莉子 提交于 2019-12-25 04:32:33

问题


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?


回答1:


you can do that by adding the following line before save

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

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

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



来源:https://stackoverflow.com/questions/18864007/reduce-file-size-with-dotnetzip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!