Change Database FileName And Copy Into Existing Folder

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Webbyz

    #1

    Change Database FileName And Copy Into Existing Folder


    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?

  • Webbyz

    #2
    Re: Change Database FileName And Copy Into Existing Folder

    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 !

    Comment

    • Dragon

      #3
      Re: Change Database FileName And Copy Into Existing Folder

      Hi,

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

      ~
      File.Copy(OpenF ileDialog1.File Name,
      Path.Combine(Ap plication.Start upPath, "wasa.mdb") , True) REM Untested
      ~

      HTH,
      Roman

      "Webbyz" <mail.webb@gmai l.com> ???????/???????? ? ???????? ?????????:
      news:1127839727 .852532.236960@ o13g2000cwo.goo glegroups.com.. .[color=blue]
      > I forgot to add this although some might realize it. I need the[/color]
      renamed[color=blue]
      > file (wasa.mdb) to be inserted back into the /bin/ folder where my
      > application is run. Thanks !
      >[/color]


      Comment

      • Webbyz

        #4
        Re: Change Database FileName And Copy Into Existing Folder

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

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

        Additional information: Empty file name is not legal.



        What's up with that?

        Comment

        • Dragon

          #5
          Re: Change Database FileName And Copy Into Existing Folder

          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.F ileName,
          Path.Combine(Ap plication.Start upPath, "wasa.mdb") , True)
          MessageBox.Show ("You restored a backup: " &
          Path.GetFileNam e(ofp.FileName) )
          Else
          MessageBox.Show ("User doesn't want to restore a backup!")
          End If
          ~

          Roman

          "Webbyz" <mail.webb@gmai l.com> ???????/???????? ? ???????? ?????????:
          news:1127845086 .658470.15960@g 49g2000cwa.goog legroups.com...[color=blue]
          > I used the code and I imported System.IO and here is the error I got..
          >
          > An unhandled exception of type 'System.Argumen tException' occurred in
          > mscorlib.dll
          >
          > Additional information: Empty file name is not legal.
          >
          >
          >
          > What's up with that?
          >[/color]


          Comment

          • Webbyz

            #6
            Re: Change Database FileName And Copy Into Existing Folder

            Dragon You Rock! Works like a charm. Thanks a bunch!

            Comment

            Working...