Sort FileInfo in ListBox

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I'm using the below code to populate a ListBox with file content
information. Sorting the information alpha/numerically is now an
issue. Would someone please let me know the best aproach to take in
doing this.

Thank You

***************************

if (di.Exists)
{
FileInfo[] files = di.GetFiles();
for (int i = 0; i < files.Length; i++)
{
ListBox1.Items.Add(files.Name);
}
}
 
I think that I should also add that the ListBox is on an ASPX.

Hmm - if you'd said that in the first place (or even posted in the aspnet
newsgroup), I'd not have suggested the Sorted property, and you would have
had your answer straightaway...

No matter, here we go:

if (di.Exists)
{
FileInfo[] files = di.GetFiles();
ArrayList lstFiles = new ArrayList();
for (int i = 0; i < files.Length; i++)
{
lstFiles.Add(files.Name);
}
lstFiles.Sort();
listBox1.DataSource = lstFiles;
listBox1.DataBind();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top