Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

Save file to location with the SaveFileDialog but the file allready exists!

Hi,

What can I do to save a file to a certain location with the SaveFileDialog but the same file allready exists! I get an message to override it. And I click Yes. But then I get an error:
   
System.IO.IOExeption: the file c:\Users\Peter\Desktop\DBRoot.bak already exists.

        private void bbBackup_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string pathDB = Application.StartupPath + "\\DBRoot.mdb";
            glucsTA.Update(glucsDS);
            glucsDS.AcceptChanges();
            suppTA.Update(suppDS);
            suppDS.AcceptChanges();
            favorTA.Update(favorDS);
            favorDS.AcceptChanges();
            calenTA.Update(calenDS);
            calenDS.AcceptChanges();
            SaveFileDialog saveFileDlg = new SaveFileDialog();
            saveFileDlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            saveFileDlg.Filter = "Backup File (*.bak)|*.bak";
            saveFileDlg.FileName = "DBRoot.bak";
            try
            {
                if (saveFileDlg.ShowDialog() == DialogResult.OK)
                {
                    System.IO.File.Copy(pathDB, saveFileDlg.FileName);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.ToString());
            }
        }

Open in new window


Greetings, Peter Kiers
Avatar of Matti
Matti
Flag of Finland image

use date/time in the default file name then it does not exist.
Avatar of Peter Kiers

ASKER

I don't understand could you help me?
Greetings, Peter
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ah, yes indeed James your right. Thank for the solution.
Greetings, Peter Kiers