10 Replies - 2042 Views - Last Post: 08 April 2012 - 01:22 AM Rate Topic: -----

#1 jhedonghae   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Automatically detect a drive for Backup a database

Posted 04 April 2012 - 01:42 AM

i have here a code for my back up:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dbload As String = Application.StartupPath + "\Enrollment System.accdb"
Dim backupdb As String = "G:{0:yyyyMMdd}" + ".accdb"
System.IO.File.Copy(dbload, String.Format(backupdb, Date.Today), True)
MsgBox("DB Backup Successful")
End Sub


but this code sets a certain drive where my database is save..what i wanted is that on how to automatically detect a drive then save it if their is available drive and if not then probably would prompt that their is no destination for saving..

please help me

Is This A Good Question/Topic? 0
  • +

Replies To: Automatically detect a drive for Backup a database

#2 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: Automatically detect a drive for Backup a database

Posted 04 April 2012 - 01:50 AM

Check if the default path exists.
If Not---> Prompt user for a path to save to. Use SaveFileDialog.
If Yes---> Save it there
Was This Post Helpful? 0
  • +
  • -

#3 jhedonghae   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: Automatically detect a drive for Backup a database

Posted 04 April 2012 - 01:53 AM

how do i add that?
Was This Post Helpful? 0
  • +
  • -

#4 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: Automatically detect a drive for Backup a database

Posted 04 April 2012 - 01:58 AM

Directory.Exists
If Not IO.Directory.Exists(defaultpath) Then
Dim sdialog As New SaveFileDialog
sdialog.Description = "Choose a path to save to"
If sdialog.ShowDialog = System.Windows.Forms.DislogResult.OK Then
'use the path from the dialog's FileName property to copy the file
End If
Else
'do the regular thing
End If


Was This Post Helpful? 0
  • +
  • -

#5 jhedonghae   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: Automatically detect a drive for Backup a database

Posted 04 April 2012 - 04:27 AM

View PostDimitriV, on 04 April 2012 - 01:58 AM, said:

Directory.Exists
If Not IO.Directory.Exists(defaultpath) Then
Dim sdialog As New SaveFileDialog
sdialog.Description = "Choose a path to save to"
If sdialog.ShowDialog = System.Windows.Forms.DislogResult.OK Then
'use the path from the dialog's FileName property to copy the file
End If
Else
'do the regular thing
End If




i get an error with the default path and sdialog.Description..what should i do...am i still gonna use my code with your code?
Was This Post Helpful? 0
  • +
  • -

#6 jhedonghae   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: Automatically detect a drive for Backup a database

Posted 04 April 2012 - 04:47 AM

can you please teach it to me step by step because i'm not really good in vb coz i'm just a newbie
Was This Post Helpful? 0
  • +
  • -

#7 jhedonghae   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: Automatically detect a drive for Backup a database

Posted 06 April 2012 - 07:36 AM

please anyone help me solved this
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim dbload As String = Application.StartupPath + "\Enrollment System.accdb"
    Dim driveletter As String = GetDrives().Item(GetDrives.Count - 1)
    Dim backupdb As String = driveletter & ":\{0:yyyyMMdd}" + ".accdb"
    System.IO.File.Copy(dbload, String.Format(backupdb, Date.Today), True)
    MsgBox("DB Backup Successful")
End Sub
Public Function GetDrives() As ArrayList
    Dim drives As New ArrayList
    For Each drive As DriveInfo In My.Computer.FileSystem.Drives
        drives.Add(drive.Name)
    Next
    Return drives
End Function
Posted Image
but i get an error as seen in the attach image

This post has been edited by jhedonghae: 06 April 2012 - 07:38 AM

Was This Post Helpful? 0
  • +
  • -

#8 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: Automatically detect a drive for Backup a database

Posted 06 April 2012 - 09:41 PM

If the name of the file will contain any of these characters:
\ / : * ? " < > |
Then it will not work.
Was This Post Helpful? 0
  • +
  • -

#9 jhedonghae   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: Automatically detect a drive for Backup a database

Posted 07 April 2012 - 04:16 AM

View PostDimitriV, on 06 April 2012 - 09:41 PM, said:

If the name of the file will contain any of these characters:
\ / : * ? " < > |
Then it will not work.

Enrollment System.accdb is the name of the file
Was This Post Helpful? 0
  • +
  • -

#10 jhedonghae   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: Automatically detect a drive for Backup a database

Posted 07 April 2012 - 11:55 PM

View Postjhedonghae, on 07 April 2012 - 04:16 AM, said:

View PostDimitriV, on 06 April 2012 - 09:41 PM, said:

If the name of the file will contain any of these characters:
\ / : * ? " < > |
Then it will not work.

Enrollment System.accdb is the name of the file

now it's working...thanks a lot..but i have just one question...what if their is no available drive how do i prompt a message that insert a drive first???
Was This Post Helpful? 0
  • +
  • -

#11 jhedonghae   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: Automatically detect a drive for Backup a database

Posted 08 April 2012 - 01:22 AM

my problem is solved..thanks everyone..Godbless
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1