如何在兩個日期之間列出文件。現在它遍歷文件夾中的每個文件並返回所有文件。在兩個日期之間獲取文件
protected void btnListItems_Click(object sender, EventArgs e)
{
lblMessage.Visible = false;
//lblEnddatse.Visible = true;
Boolean status = true;
Util objUtil = new Util();
String Message = "";
DateTime SDate = new DateTime();
DateTime EDate = new DateTime();
string str = "";
DataTable tbl = new DataTable();
DataTable dt = new DataTable();
DataRow dr;
String[] s1;
//DirectoryInfo d = new DirectoryInfo();
s1 = Directory.GetFiles(@"C:/PCRequestFiles");
for (int i = 0; i <= s1.Length - 1; i++)
{
if (i == 0)
{
//Add Data Grid Columns with name
dt.Columns.Add("FileName");
dt.Columns.Add("GeneratedTime");
}
//Get each file information
FileInfo f = new FileInfo(s1[i]);
FileSystemInfo f1 = new FileInfo(s1[i]);
dr = dt.NewRow();
//Get File name of each file name
dr["FileName"] = f1.Name;
dr["GeneratedTime"] = f1.CreationTime.Date.ToString("dd/MM/yyyy");
string a = f1.CreationTime.Date.ToString("dd/MM/yyyy");
//Insert collected file details in Datatable
string fromdate = txtFromDate.Text.ToString();
string todate = txtToDate.Text.ToString();
dt.Rows.Add(dr);
if ((f.Length/1024) > 5000)
{
lblMessage .Text = "" + f1.Name + " had reach its size limit.";
}
else
{ }
}
if (dt.Rows.Count > 0)
{
gvFileGenStatus.DataSource = dt;
gvFileGenStatus.DataBind();
}
}
我試着給的條件,但它有沒有work.Is仍要使用日期過濾器以文件名列表從目錄。 感謝您提前提供所有幫助)。
「如何列出兩個日期之間的文件」什麼是你指的是兩個日期?創建時間? – Jannik