备份文件及恢复文件[WEB学习实例]

来源:互联网 发布:java深度优先遍历算法 编辑:程序博客网 时间:2024/06/06 09:46

protected void Button11_Click(object sender, EventArgs e)//备份
    { Bei_Fen_data(); }

    protected void 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();
        if (!File.Exists(Server.MapPath(@"~/DataBasc/" + "备份" + DateTimes + ".aspx")))
        {
            File.Copy(Server.MapPath(@"~/Data/So.aspx"), Server.MapPath(@"~/DataBasc/" + "备份" + DateTimes + ".aspx"));
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "tixin", "alert('备份成功。')", true);
        }
        else { System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "tixin", "alert('备份失败?')", true); }
    }

    protected void Button12_Click(object sender, EventArgs e)//还原
    {
        File.Copy(Server.MapPath(@"~/DataBasc/" + DropDownList8.Text), Server.MapPath(@"~/Data/So.aspx"), true);
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "tixin", "alert('恢复成功。')", true);
    }

原创粉丝点击