delete file

Dec 6, 2013 at 5:59 PM
I was changing your code, when it selection to generate compressed file (ZIP) , after the backup will be deleted the SQL file.
But this not working you could help me.
code:
#region Zip Output File
            if (ExportInfo.ZipOutputFile)
            {
                string fileDelete = ExportInfo.FileName;
                
                using (ZipFile zip = new ZipFile())
                {
                    zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
                    string newZipFile = Path.GetDirectoryName(ExportInfo.FileName) + "\\" + Path.GetFileNameWithoutExtension(ExportInfo.FileName) + ".zip";
                    zip.AddFile(ExportInfo.FileName);
                    zip.Save(newZipFile);
                    ExportInfo.FileName = newZipFile;
                }

                __if (System.IO.File.Exists(fileDelete))
                {
                    System.IO.File.Delete(fileDelete);
                }__
            }
            #endregion
Coordinator
Dec 7, 2013 at 2:59 PM
Edited Dec 7, 2013 at 3:00 PM
Hi, I am re-writing the whole library. In the new MySqlBackup.NET, DotNetZip is no more required to zip the file.
I will release a new version of this library in these few days.

As for the current problem mentioned by you, you can't delete the file there.
This is because the file stream is still opening.
You can delete the file after the file stream is closed.

try to locate this block of code:
private void ExportExecute()
{
    try
    {
        using (textWriter = new StreamWriter(_exportInfo.FileName, false, utf8WithoutBOM))
        {
            ExportStart();
        }
    }
    .....
You capture the string value of fileDelete and delete the file here:
private void ExportExecute()
{
    try
    {
        using (textWriter = new StreamWriter(_exportInfo.FileName, false, utf8WithoutBOM))
        {
            ExportStart();
        }
    }
    if (System.IO.File.Exists(fileDelete))
    {
        System.IO.File.Delete(fileDelete);
    }        
    .....