using System.IO;
.
.
.

private bool Backupdb()
{
string sFile = Application.StartupPath + @"\dbbasic.mdb";
string tFile = txtbak.Text+@"/dbbasic.mdb";
if(!File.Exists(sFile))
{
rLink = "无法找到数据库文件!\n"+sFile;
MessageBox.Show (rLink);
return false;
}
if(File.Exists (tFile)&&ckOverWrite.Checked)
{
string msg;
msg = "目标路径已经存在同名文件,是否覆盖?\n";
DateTime ct = File.GetCreationTime (tFile);
DateTime lw = File.GetLastWriteTime (tFile);
msg += "文件名:"+tFile+"\n";
msg += "建立时间:"+ct.ToString ()+"\n";
msg += "最后写入时间:"+lw.ToString ();
if(MessageBox.Show (msg,"目标文件已存在",MessageBoxButtons.YesNo,MessageBoxIcon.Question)!=DialogResult.Yes)
{
rLink = "已取消";
return false;
}
}
try
{
File.Copy (sFile,tFile,true);
rLink = "备份成功!";
}
catch(FileNotFoundException e)
{
MessageBox.Show (e.Message );
rLink = "备份数据库失败!";
return false;
}
catch(DirectoryNotFoundException e)
{
MessageBox.Show (e.Message );
rLink = "备份数据库失败!";
return false;
}
catch(IOException e)
{
MessageBox.Show (e.Message );
rLink = "备份数据库失败!";
return false;
}
return true;
}