private void BindToDG()
{
Directory.SetCurrentDirectory(Operater.Server.ServerPath()+"backup\\");
string fd=Directory.GetCurrentDirectory();
string[] fileEntries=Directory.GetFiles(fd,"*.bak");
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("文件名称", typeof(string)));
dt.Columns.Add(new DataColumn("创建时间", typeof(DateTime)));
dt.Columns.Add(new DataColumn("修改时间", typeof(DateTime)));
foreach(string filename in fileEntries)
{
string d=Operater.Server.ServerPath()+"backup\\";
int i=d.Length ;
dr = dt.NewRow();
dr[0]=filename.Remove(0,i);
dr[1]=File.GetCreationTime(filename);
dr[2]=File.GetLastAccessTime(filename);
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
this.DataGrid1.DataSource=dv;
this.DataGrid1.DataBind();
}
删除操作:{
Directory.SetCurrentDirectory(Operater.Server.ServerPath()+"backup\\");
string fd=Directory.GetCurrentDirectory();
string[] fileEntries=Directory.GetFiles(fd,"*.bak");
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("文件名称", typeof(string)));
dt.Columns.Add(new DataColumn("创建时间", typeof(DateTime)));
dt.Columns.Add(new DataColumn("修改时间", typeof(DateTime)));
foreach(string filename in fileEntries)
{
string d=Operater.Server.ServerPath()+"backup\\";
int i=d.Length ;
dr = dt.NewRow();
dr[0]=filename.Remove(0,i);
dr[1]=File.GetCreationTime(filename);
dr[2]=File.GetLastAccessTime(filename);
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
this.DataGrid1.DataSource=dv;
this.DataGrid1.DataBind();
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string path=Operater.Server.ServerPath()+"backup\\"+(string)this.DataGrid1.Items[e.Item.ItemIndex].Cells[1].Text.ToString();
File.Delete(path);
this.BindToDG();
}
{
string path=Operater.Server.ServerPath()+"backup\\"+(string)this.DataGrid1.Items[e.Item.ItemIndex].Cells[1].Text.ToString();
File.Delete(path);
this.BindToDG();
}