private void Button2_Click(object sender, EventArgs e) { try { foreach (System.Diagnostics.Process process in System.Diagnostics.Process.GetProcessesByName("MSACCESS")) { if (process.MainWindowTitle.Contains("fatih2541.accdb")) { process.Kill(); } } GC.Collect(); GC.WaitForPendingFinalizers(); OpenFileDialog dlg = new OpenFileDialog { Filter = "Microsoft Access Database(2002-2003) (*.mdb)|*.mdb|Microsoft Access Database(2007-2009) (*.accdb)|*.accdb", // If you want to keep default extensiion *.mdb then FilterIndex = 1 or if you want to keep default extension *.accdb then FilterIndex=2 FilterIndex = 2, InitialDirectory = Environment.CurrentDirectory + @"\Backup"}; if (dlg.ShowDialog() == DialogResult.OK) { MessageBox.Show("Database to restore " + dlg.FileName); } string PathToRestoreDB = Environment.CurrentDirectory + @"\fatih2541.accdb"; string Filetorestore = dlg.FileName; // Rename Current Database to .Bak File.Move(PathToRestoreDB, PathToRestoreDB); //Restore the Database From Backup Folder File.Copy(Filetorestore, PathToRestoreDB, true); MessageBox.Show("It was replaced with the database backup.", "The new information has been transfered.", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("The process was canceled " + ex.Message); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)