private void btnSave_Click(object sender, EventArgs e) { if (txtLocation.Text == string.Empty) { MessageBox.Show("Please select Backup File Location", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { string FileName = "'"+txtLocation.Text + "Backup"; string BackupFileName = "" + FileName + ".bak'"; string BackupZipFileName = "" + FileName + ".zip'"; cn.Open(); cmd.CommandText = @"BACKUP DATABASE POS TO DISK = " + BackupFileName; cmd.CommandType = CommandType.Text; cmd.Connection = cn; dr = cmd.ExecuteReader(); dr.Close(); cn.Close(); // byte[] bt = File.ReadAllBytes(BackupFileName); FileStream fStream = File.Create(BackupZipFileName); GZipStream gZip = new GZipStream(fStream, CompressionMode.Compress); //zip process //delete backupfilename //string sZipFileName = BackupFileName.Replace(".bak", ".zip"); //byte[] bt = File.ReadAllBytes(sZipFileName); //FileStream fStream = File.Create(sZipFileName, bt.Length, FileOptions.Encrypted); // GZipStream gZip = new GZipStream(fStream, CompressionMode.Compress); // gZip.Write(bt, 0, bt.Length); // gZip.Close(); // gZip.Dispose(); MessageBox.Show("Backup Successfull", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch (Exception ex) { cn.Close(); MessageBox.Show(ex.Message); } }
Quote:DotNetZip is a FAST, FREE class library and toolset for manipulating zip files. Use VB, C# or any .NET language to easily create, extract, or update zip files
using (ZipFile zip = new ZipFile()) { zip.Password= "123456!"; //password for all files zip.AddFile("ReadMe.txt"); zip.AddFile("7440-N49th.png"); zip.AddFile("2005_Annual_Report.pdf"); zip.Save("Backup.zip"); }
FileStream fStream = File.Create(BackupZipFileName); GZipStream gZip = new GZipStream(fStream, CompressionMode.Compress);
FileStream
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)