{
DataRow drow;
DataTable dt = SetDataTable();
DirectoryInfo dir = new DirectoryInfo(filepath);
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
drow = dt.NewRow();
drow["FILENAME"] = file.Name;
drow["FILEPATH"] = file.FullName;
drow["FILESIZE"] = GetSizeInMB(file.Length) + " MB";
dt.Rows.Add(drow);
}
if (dt.Rows.Count > 0)
{
grdDirList.DataSource = dt;
grdDirList.DataBind();
} }
private DataTable SetDataTable()
{
DataTable dt = new DataTable();
try
{
DataColumn dcol = new DataColumn("FILENAME", typeof(System.String));
dt.Columns.Add(dcol);
dcol = new DataColumn("FILEPATH", typeof(System.String));
dt.Columns.Add(dcol);
dcol = new DataColumn("FILESIZE", typeof(System.String));
dt.Columns.Add(dcol);
}catch{} return dt;
}
Hope it helps....