السلام عليكم ،
استخدم هذا الكود لعمل نسخة احتياطية واسترجاعها ولكن عند استرجاع النسخة الاحتياطية يظهر هذا الخطا
Cannot create a file when that file already exists.
private void button1_Click(object sender, EventArgs e)
{
string CurrentDatabasePath = Environment.CurrentDirectory + @"\jepdata.mdb";
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
string PathtobackUp = fbd.SelectedPath.ToString();
File.Copy(CurrentDatabasePath, PathtobackUp + @"\jepdata.mdb", true);
MessageBox.Show("تم انشاء نسخة احتياطية بنجاح! ");
}
}
private void button2_Click(object sender, EventArgs e)
{
string PathToRestoreDB = Environment.CurrentDirectory + @"\jepdata.mdb";
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
string Filetorestore = ofd.FileName;
// Rename Current Database to .Bak
File.Move(PathToRestoreDB, PathToRestoreDB + ".bak");
//Restore the Databse From Backup Folder
File.Copy(Filetorestore, PathToRestoreDB, true);
}
}واذا امكن هل يمكن انشاء نسخة احتياطية في نفس مكان محدد تلقائي يومياً مثلاً