NinetyNine's Treasure

| 积淀*育创新 智慧创造价值|

导航

DataGrid邦定文件夹内的指定类型文件

Posted on 2007-09-15 02:34  (NineTyNine)  阅读(350)  评论(0编辑  收藏  举报
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();
        }
删除操作:
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();
        }