C#不接受DotNetZip压缩中的路径

时间:2015-03-04 16:11:58

标签: c# path dotnetzip

我正在努力使用C#,Ionic.Zip和路径声明 错误消息是:不支持路径格式 路径看起来正确,所以不知道这里发生了什么......
这是我的代码:

string datetime = System.DateTime.Now.ToString("G");
datetime = String.Format("{0:yyyy_MM_dd}", datetime); 

string workingPath = @"C:\Users\udgru\Documents\Visual Studio 2013\Projects\Skeleton\Skeleton\bin\Debug";
string backupDir = System.IO.Path.Combine(workingPath, "UserData");
string outputFile = "Backup_" + datetime + ".zip";

MessageBox.Show(workingPath);
// Output: C:\Users\udgru\Documents\Visual Studio 2013\Projects\Skeleton\Skeleton\bin\Debug
MessageBox.Show(backupDir);
// Output: C:\Users\udgru\Documents\Visual Studio 2013\Projects\Skeleton\Skeleton\bin\Debug\UserData
MessageBox.Show(outputFile);
// Output: Backup_2015_03_04 17:26:44.zip

        try
        {
            using (ZipFile zip = new ZipFile())
            {

                zip.AlternateEncoding = Encoding.UTF8;
                zip.AlternateEncodingUsage = Ionic.Zip.ZipOption.Always;
                zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
                zip.Comment = "This zip was created at " + datetime;
                zip.AddDirectory(backupDir);
                zip.Save(outputFile);

                MessageBox.Show("Backup successfully created.");

                FlyoutSettings.IsOpen = false;
            }
        }
        catch(Exception error)
        {
            MessageBox.Show(error.Message.ToString());
        } 

0 个答案:

没有答案