[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2014-01-26
4
Medium Priority
?
254 Views
Last Modified: 2014-01-26
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
0
Comment
Question by:peterkiers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Matti
ID: 39810261
use date/time in the default file name then it does not exist.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 39810262
I don't understand could you help me?
Greetings, Peter
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 39810376
The role of the SaveFileDialog is to select a file. It flags the user if the file already exists, but does nothing else. It's you job to react.

It's your Copy that causes the problem. The way you call it, overwrite is not enabled.

Try passing true as a third parameter to Copy. This enables overwriting the file.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 39810584
Ah, yes indeed James your right. Thank for the solution.
Greetings, Peter Kiers
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question