Change Database FileName And Copy Into Existing Folder

  • Thread starter Thread starter Webbyz
  • Start date Start date
W

Webbyz

Using vb.net

Hello. Here is the problem that I am having. I have a program which
makes a copy of my working database (wasa.mdb) and saves it to another
folder (/bin/backup/) with the filename (9-27-2005,1210PM.mdb) *Note
This Is The Current System Date And Time Of The Save.*

I would like to have the function where when the user selects The
"Restore Database" button (btnRestore) that it will use an Open File
Dialog box and let them select which version of the database they would
like to use for the restore. Then I need the functionallity where once
the database version is selected, it will rename the
(9-27-2005,1210PM.mdb) to (wasa.mdb) so that my application can use the
database. It can overwrite the current file as I will throw the
functionallity to save the database before the restore. Can anyone help?
 
I forgot to add this although some might realize it. I need the renamed
file (wasa.mdb) to be inserted back into the /bin/ folder where my
application is run. Thanks !
 
Hi,

Take a look at File.Copy method, e.g.:

~
File.Copy(OpenFileDialog1.FileName,
Path.Combine(Application.StartupPath, "wasa.mdb"), True) REM Untested
~

HTH,
Roman
 
I used the code and I imported System.IO and here is the error I got..

An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll

Additional information: Empty file name is not legal.



What's up with that?
 
Have you already shown your OpenFileDialog?

Sample:

~
Dim ofp As New OpenFileDialog
ofp.Filter = "Access Databases (*.mdb)|*.mdb"
If ofp.ShowDialog(Me) = DialogResult.OK Then
File.Copy(ofp.FileName,
Path.Combine(Application.StartupPath, "wasa.mdb"), True)
MessageBox.Show("You restored a backup: " &
Path.GetFileName(ofp.FileName))
Else
MessageBox.Show("User doesn't want to restore a backup!")
End If
~

Roman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top