in below file is showing from a directroy file but not sort out I need sort out by modified date.
please help me about this... thanks.
- private void Receipts_Load(object sender, EventArgs e)
- {
- try
- {
- string[] files = Directory.GetFiles(path);
- foreach (string file in files)
- {
- show_receipts_listbox.Items.Add(Path.GetFileName(file));
- }
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message, "Error");
- }
- }
VulpesPosted Mar 19, 2015, 10:05 AM
Try this:
private void Receipts_Load(object sender, EventArgs e)
{
try
{
DirectoryInfo di = new DirectoryInfo(path);
FileInfo[] fia = di.GetFiles();
FileInfo t = null;
for (int p = 0; p <= fia.Length - 2; p++)
{
for (int i = 0; i <= fia.Length - 2; i++)
{
if (fia[i].LastWriteTime > fia[i + 1].LastWriteTime)
{
t = fia[i + 1];
fia[i + 1] = fia[i];
fia[i] = t;
}
}
}
foreach (FileInfo fi in fia)
{
show_receipts_listbox.Items.Add(fi.Name);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
Amar SrivastavaPosted Sep 19, 2017, 7:39 AM
{
try
{
string[] files = Directory.GetFiles(path);
foreach (string file in files)
{
show_receipts_listbox.Items.Add(Path.GetFileName(file));
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
Feroz KhanPosted Mar 22, 2015, 3:36 PM
Feroz KhanPosted Mar 22, 2015, 3:09 PM
now i want search field how can i search listbox value with textbox........
VulpesPosted Mar 20, 2015, 11:12 AM
Feroz KhanPosted Mar 20, 2015, 9:31 AM
VulpesPosted Mar 19, 2015, 11:16 AM
Jignesh TrivediPosted Mar 19, 2015, 10:18 AM
Hi,
using Array.sort method, you can sort the array...
string[] files = Directory.GetFiles(path);
Array.Sort(files);
hope this will help you.
Feroz KhanPosted Mar 19, 2015, 3:40 AM
VulpesPosted Mar 18, 2015, 7:14 PM
using System.Linq;
You also need to be using .NET 3.5 (VS 2008) or later.
Feroz KhanPosted Mar 18, 2015, 4:39 PM
orderBY not accepting..
Feroz KhanPosted Mar 18, 2015, 4:37 PM
VulpesPosted Mar 18, 2015, 3:43 PM
private void Receipts_Load(object sender, EventArgs e)
{
try
{
DirectoryInfo di = new DirectoryInfo(path);
string[] files = di.GetFiles()
.OrderBy(fi => fi.LastWriteTime)
.Select(fi => fi.FullName)
.ToArray();
foreach (string file in files)
{
show_receipts_listbox.Items.Add(Path.GetFileName(file));
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}