我已经为备份我的数据库做了这个 工作正常....
private void backupDatabase()
{
txtbackup.AppendText("Starting Backup...");
Process sd = null;
const string backupcmd = @"C:\wamp\www\access\mysqldump.exe";
string filepath = @"C:\folder\Access\";
string dbHost = "local";
string dbuser = "root";
string dbName = "access";
string backupName = "Backup.sql";
ProcessStartInfo r1 = new ProcessStartInfo(backupcmd, string.Format("-h {0} -u {1} {2} -r {3}", dbHost, dbuser, dbName, backupName));
r1.CreateNoWindow = true;
r1.WorkingDirectory = filepath;
r1.UseShellExecute = false;
r1.WindowStyle = ProcessWindowStyle.Minimized;
r1.RedirectStandardInput = false;
sd = Process.Start(r1);
sd.WaitForExit();
if (!sd.HasExited)
{
sd.Close();
}
sd.Dispose();
r1 = null;
sd = null;
txtbackup.Clear();
txtbackup.AppendText("Backup is Finished");
}
它的工作正常...但我想将backup.sql存储为此路径中的zip文件
@"C:\folder\Access\";
我有这个库Ionic.Zip.Reduced但我不知道如何压缩文件并存储在给定的路径....
答案 0 :(得分:3)
该库非常易于使用:
using (var zip = new ZipFile())
{
zip.AddFile("Backup.sql");
zip.Save(@"C:\folder\Access\"Backup.zip");
}
即使their homepage包含足以供您使用的样本。
答案 1 :(得分:-1)
您应该使用此压缩库,还是this可以选择一个?