如何使用 ionic 库压缩文件

发布于 2024-12-09 06:53:27 字数 1233 浏览 0 评论 0原文

我已经做了这个来备份我的数据库 它工作正常......

    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 但我不知道如何压缩文件并存储在给定的路径....

I have done this one for backup my database
its working fine ....

    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");

    } 

its working fine ...but i want to store the backup.sql as a zip file in this path

@"C:\folder\Access\";

i have got this library Ionic.Zip.Reduced but i dont know how to zip the file and stored in the given path....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔嚣张 2024-12-16 06:53:27

该库使用起来非常简单:

using (var zip = new ZipFile())
{
    zip.AddFile("Backup.sql");

    zip.Save(@"C:\folder\Access\"Backup.zip");
}

甚至他们的主页也包含足够好的示例供您使用。

The library is pretty simple to use :

using (var zip = new ZipFile())
{
    zip.AddFile("Backup.sql");

    zip.Save(@"C:\folder\Access\"Backup.zip");
}

And even their homepage contains samples good enough for your use.

衣神在巴黎 2024-12-16 06:53:27

您应该使用此压缩库,或者这个可能是一种选择?

You should use this compression library or this one may be an option?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文