I am creating a backup of a access database.
The user selects the file to copy, and that file is saved in c:\autotime\backups\
If the user selects a file called test.mdb and in c:\autotime\backups\ theres a test.mdb a messagebox is displayed with yes no buttons.
if yes is pressed, delete that file and copy the one the user selected.
However, it will not delete.
Thanks in advance
The user selects the file to copy, and that file is saved in c:\autotime\backups\
If the user selects a file called test.mdb and in c:\autotime\backups\ theres a test.mdb a messagebox is displayed with yes no buttons.
if yes is pressed, delete that file and copy the one the user selected.
However, it will not delete.
VB.NET:
Private Sub mnuFileBackup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileBackup.Click
Me.OpenFileDialog1.Filter = "mdb files (*.mdb)|*.mdb"
Me.OpenFileDialog1.InitialDirectory = "C:\"
Try
If OpenFileDialog1.ShowDialog <> DialogResult.Cancel Then
MessageBox.Show(OpenFileDialog1.FileName.Substring(OpenFileDialog1.FileName.LastIndexOf("\")))
If System.IO.File.Exists("c:\AutoTime\backups" & OpenFileDialog1.FileName.Substring(OpenFileDialog1.FileName.LastIndexOf("\"))) = True Then
MessageBox.Show("File exists. Delete?", "AutoTime: error", MessageBoxButtons.YesNo)
If DialogResult = DialogResult.Yes Then
Dim fi As New FileInfo("c:\AutoTime\backups\mydb.mdb")
fi.Delete()
End If
Else
File.Copy(OpenFileDialog1.FileName, "c:\AutoTime\backups" & "\" & OpenFileDialog1.FileName.Substring(OpenFileDialog1.FileName.LastIndexOf("\")))
End If
End If
Catch
End Try
End Sub
Thanks in advance