CSDN博客

img dcboy

读取文件列表到datatable

发表于2004/7/17 20:25:00  880人阅读

private DataTable datatable;

private DataTable CreateDataSource()
??{
???DataTable dt = new DataTable();
???DataColumn col;

???col=new DataColumn();
???col.DataType=System.Type.GetType("System.Int32");
???col.ColumnName="ID";
???col.ReadOnly=true;
???col.AutoIncrement=true;
???col.AutoIncrementSeed=1;
???col.AutoIncrementStep=1;
???dt.Columns.Add(col);

???col=new DataColumn();
???col.DataType=System.Type.GetType("System.Int32");
???col.ColumnName="ParentID";
???col.ReadOnly=false;
???col.Unique=false;
???col.DefaultValue=int.Parse("0");
???dt.Columns.Add(col);

???dt.Columns.Add("filetype", typeof(int));
???dt.Columns.Add("filename", typeof(string));
???dt.Columns.Add("filesize",typeof(int));
???dt.Columns.Add("LastWriteTime", typeof(DateTime));
???return dt;
??}

public DataTable GetFolder()
??{
???CheckFolder();

???//DataTable dt = CreateDataSource();
???datatable=CreateDataSource();
???DirectoryInfo di=new DirectoryInfo(GetCurDir());
???GetFolder(0,di);
???datatable.AcceptChanges();
???return datatable;
??}

??private void GetFolder(int ParentID,DirectoryInfo dirinfo)
??{
???foreach(DirectoryInfo di in dirinfo.GetDirectories())
???{
????DataRow row;
????row=datatable.NewRow();
????row["ParentID"] = ParentID;
????row["filetype"] = 0; //dir
????row["filename"] = di.Name;
????row["filesize"] = 0;
????row["LastWriteTime"] = di.LastWriteTime;
????datatable.Rows.Add(row);
????int lpid=(int)datatable.Rows[datatable.Rows.Count-1]["ID"]; //获得最后一条记录得ID
????GetFolder(lpid,di);
???}
??}

0 0

相关博文

我的热门文章

img
取 消
img