ACCESS网站示例-连载-数据库备份与还原类文件

时间:2021-03-08 09:59:20


using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;



/// <summary>
///Bei_Fen_DaTa 的摘要说明:数据库备份、还原操作。
/// </summary>
public class Bei_Fen_DaTa
{
TiShi_XinXi Ts_XinXi = new TiShi_XinXi();

public Bei_Fen_DaTa()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
///Bei_Fen_data 的摘要说明:数据库备份操作。
/// </summary>
public string Bei_Fen_data()//数据库备份
{
string DateTimes = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString();
string ChenGong = "";
if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(@"~\bakDataBasc\" + "数据库备份" + DateTimes + ".aspx")))
{
File.Copy(System.Web.HttpContext.Current.Server.MapPath(@"~\App_Data\Socut.aspx"), System.Web.HttpContext.Current.Server.MapPath(@"~\bakDataBasc\" + "数据库备份" + DateTimes + ".aspx"));
ChenGong = "完成";
/*if (url != "")
{ System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('数据库备份成功。');location='" + url + "';</script>"); }
else
{ System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('数据库备份成功。')</script>"); }*/
}
return ChenGong;
//File.Delete(Server.MapPath(@"~\bei-fen\Socut.aspx"));
//File.Copy(Server.MapPath(@"~\App_Data\Socut.aspx"), Server.MapPath(@"~\bei-fen\Socut.aspx"));
//System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "友情提示!", "alert('数据库备份成功。')", true);
}
/// <summary>
///HuanYuan_data 的摘要说明:数据库还原操作。
/// </summary>
public void HuanYuan_data(string ShuJu_MingCheng)//还原数据库
{
File.Copy(System.Web.HttpContext.Current.Server.MapPath(@"~\bakDataBasc\" + ShuJu_MingCheng), System.Web.HttpContext.Current.Server.MapPath(@"~\App_Data\Socut.aspx"), true);
}
}