Atul Rokade

Atul Rokade

  • NA
  • 141
  • 43.7k

how to create backup file without using save or open dialog

Apr 1 2017 2:39 AM
Hi all,
 
   Iam creating back up file of ms-access database code working fine when i use FolderBrowserDialog box but i want back up should store automatically when i close form for specific directory  
 
i'm tried below code but its not working
public void create_Directory()
{
 
String Application_Folder = @"D:\Medical_reports";
if (!Directory.Exists(Application_Folder))
{
Directory.CreateDirectory(Application_Folder);
}
 
string Back_UP = Path.Combine(Application_Folder, "Back_UP");
if (!Directory.Exists(Back_UP))
{
Directory.CreateDirectory(Back_UP);
}
 
 
private void Login_Page_FormClosing(object sender, FormClosingEventArgs e)
{
 
create_Directory();
string file_name = @"\Medical.accdb";
StreamWriter sw = new StreamWriter(file_name);
sw.Write(sw.ToString());
sw.Close();
 
 
//this code working fine but i dont want to open dialog box  
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
 string PathtobackUp = fbd.SelectedPath.ToString();
 File.Copy(CurrentDatabasePath, PathtobackUp + @"\Medical.accdb", true);
 MessageBox.Show("Back Up SuccessFull! ");
}
 

Answers (2)