using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using _5dRss.Const;
using _5dRss.lib.Data.Tool;
public partial class admin_admin_dbmanage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//çæå¤ä»½æ件å表
ListBackupFiles();
if (!Page.IsPostBack)
{
Showmsg.Visible = false;
//æ°æ®åºè·¯å¾
lilDBPath.Text = HttpContext.Current.Request.PhysicalApplicationPath + "App_Data\\" + ConfigurationSettings.AppSettings["DBFile"];
//æ°å»ºä¸ä¸ª FileInfo 对象ï¼å¹¶è·å¾æ°æ®åºæ件ç大å°ï¼ç¶å转æ¢åä½ä¸ºKB
FileInfo myFileInfo = new FileInfo(lilDBPath.Text);
lilDBSize.Text = Convert.ToString(myFileInfo.Length/1024) + " KB";
//å¦æ两个åæ°é½ä¸ä¸ºç©ºï¼å继ç»æ§è¡
if (Request.QueryString["cmd"] != null && Request.QueryString["source"] != null)
{
//å¤ä»½æ°æ®åºåæ件å
string sourceFileName = Request.QueryString["source"];
//å¦æ cmd åæ°ä¸º DelFile
if (Request.QueryString["cmd"].Equals("DelFile"))
{
//å é¤å¤ä»½æ°æ®åºæ件
File.Delete(HttpContext.Current.Request.PhysicalApplicationPath + "Backup\\" + sourceFileName);
//å·æ°å¤ä»½æ件å表
ListBackupFiles();
Showmsg.Visible = true;
Showmsg.Text = "<div align='center' style='margin-bottom:8px;'><img src='images/aL.gif' style='margin-bottom:-6px;'/><span class='alertTxt'>å é¤å¤ä»½æ°æ®åºæå!</span><img src='images/aR.gif' style='margin-bottom:-6px;'/></div>";
}
//å¦æ cmd åæ°ä¸º Restore
if (Request.QueryString["cmd"].Equals("Restore"))
{
//ç¨å¤ä»½æ件è¦çåæ件
File.Copy(HttpContext.Current.Request.PhysicalApplicationPath + "Backup\\" + sourceFileName, HttpContext.Current.Request.PhysicalApplicationPath + "App_Data\\" + ConfigurationSettings.AppSettings["DBFile"], true);
//å·æ°å¤ä»½æ件å表
ListBackupFiles();
Showmsg.Visible = true;
Showmsg.Text = "<div align='center' style='margin-bottom:8px;'><img src='images/aL.gif' style='margin-bottom:-6px;'/><span class='alertTxt'>è¿åå¤ä»½æ°æ®åºæå!</span><img src='images/aR.gif' style='margin-bottom:-6px;'/></div>";
}
}
}
}
protected void lnkbtnCompactDB_Click(object sender, EventArgs e)
{
//å缩修å¤æ°æ®åº
AccessDBtool.CompactAccessDB(SysConfig.ConnectionString, HttpContext.Current.Request.PhysicalApplicationPath + "App_Data\\" + ConfigurationSettings.AppSettings["DBFile"]);
Showmsg.Visible = true;
Showmsg.Text = "<div align='center' style='margin-bottom:8px;'><img src='images/aL.gif' style='margin-bottom:-6px;'/><span class='alertTxt'>å缩修å¤æ°æ®åºæå!</span><img src='images/aR.gif' style='margin-bottom:-6px;'/></div>";
}
protected void lnkbtnBackupDB_Click(object sender, EventArgs e)
{
string sourceFileName = HttpContext.Current.Request.PhysicalApplicationPath + "App_Data\\" + ConfigurationSettings.AppSettings["DBFile"];
string destFileName = HttpContext.Current.Request.PhysicalApplicationPath + "Backup\\" + "Backup_";
destFileName += DateTime.Now.ToString("yyyyMMddHHmmss");
destFileName += ".mbk";
//å°æ°æ®åºæ件Copyå°Backupç®å½ï¼å¦ææéåæ件就è¦çåæ件
File.Copy(sourceFileName, destFileName, true);
//çæå¤ä»½æ件å表
ListBackupFiles();
Showmsg.Visible = true;
Showmsg.Text = "<div align='center' style='margin-bottom:8px;'><img src='images/aL.gif' style='margin-bottom:-6px;'/><span class='alertTxt'>å¤ä»½æ°æ®åºæå!</span><img src='images/aR.gif' style='margin-bottom:-6px;'/></div>";
}
/// <summary>
/// çæå¤ä»½æ件å表
/// </summary>
/// <returns>æ件å表ï¼æ件详ç»ä¿¡æ¯åæä½é项çHTML代ç </returns>
public void ListBackupFiles()
{
//å¦æç®å½ä¸åå¨åå建次ç®å½
if (!Directory.Exists(HttpContext.Current.Request.PhysicalApplicationPath + "Backup\\"))
Directory.CreateDirectory(HttpContext.Current.Request.PhysicalApplicationPath + "Backup\\");
DirectoryInfo mydir = new DirectoryInfo(HttpContext.Current.Request.PhysicalApplicationPath + "Backup\\");
StringBuilder sb = new StringBuilder();
foreach (FileInfo f in mydir.GetFiles())
{
sb.Append("<a href='backup/" + f.Name + "' target='_blank'><img border='0' src='images/mdb.gif' style='margin:4px 3px -3px 0px'/>" + f.Name + "</a> <a href='?cmd=DelFile&source=" + f.Name + "' title='å é¤å¤ä»½æ件'>å é¤</a> | <a href='?cmd=Restore&source=" + f.Name + "' title='å é¤å¤ä»½æ件'>è¿åæ°æ®åº</a> | " + f.Length/1024 + " KB | " + f.CreationTime + "<br />");
}
lilBackupFileList.Text = sb.ToString();
}
}
æä¸é¢è¿å¥æ¢æä½ çæ°æ®åºå°åï¼
//æ°æ®åºè·¯å¾
// lilDBPath.Text = HttpContext.Current.Request.PhysicalApplicationPath + "App_Data\\" + ConfigurationSettings.AppSettings["DBFile"];
温馨提示:答案为网友推荐,仅供参考