dv2020
Active member
- Joined
- Dec 18, 2020
- Messages
- 30
- Programming Experience
- 1-3
Hi All
I'm using Directory.GetFiles to get a list of files, and populate the datagrid. Code is below. Everything is working, but I'm having trouble trying to get Directory.GetFiles to retrieve the list in filename or descending.
How anyone any idea if its possible, and if not via Directory.GetFiles, how to get the Datagrid to auto sort when its loaded with the list?
Thank you
Dv
I'm using Directory.GetFiles to get a list of files, and populate the datagrid. Code is below. Everything is working, but I'm having trouble trying to get Directory.GetFiles to retrieve the list in filename or descending.
How anyone any idea if its possible, and if not via Directory.GetFiles, how to get the Datagrid to auto sort when its loaded with the list?
Current Code:
private void DataGridReports(string searchTxt)
{
DgReportList.DataSource = null;
String[] files = Directory.GetFiles(reportDirPath, "*" + searchTxt + "*", SearchOption.AllDirectories);
DataTable DGRptTable = new DataTable();
DGRptTable.Columns.Add("ID");
DGRptTable.Columns.Add("RPT");
DGRptTable.Columns.Add("EXT");
for (int i = 0; i < files.Length; i++)
{
FileInfo file = new FileInfo(files[i]);
string rptid = string.Concat(file.Name.TakeWhile((c) => c != '.'));
string rptext = file.Extension;
string rptname = file.Name.Replace(rptid, "").Replace(rptext, "").Replace(".", "");
DGRptTable.Rows.Add(rptid, rptname, rptext);
}
Thank you
Dv