private void buttonSave_Click(object sender, EventArgs e)
{
//first set your application's database directory
//and the target directory where backup will be saved
String sCurrentPath;
if (ApplicationDeployment.IsNetworkDeployed)
{
currentPath=ApplicationDeployment.CurrentDeployment.DataDirectory;
}
else sCurrentPath=Application.StartupPath;
String backupFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
//the following way backup is done
string fileName = "database.mdb";
string sourcePath = currentPath;
string targetPath = backupFilePath;
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
try
{
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
System.IO.File.Copy(sourceFile, destFile, true);
bSaved = true;
}
catch (Exception ex)
{
Errorlog.SendtoWebService(ex.ToString());
MessageBox.Show("Error during backup", "application Database Error");
}
}