Mohamed Moumni

Mohamed Moumni

  • NA
  • 48
  • 8.4k

how to get files from directory in list_box1 to list_box2?

Jun 2 2017 7:19 PM
I could get the directories (2012 ,2014...) and put them in a listbox1.
  1. `DirectoryInfo[] diri_info =new DirectoryInfo(FBD.SelectedPath).GetDirectories();  
  2.   
  3. foreach (DirectoryInfo dir in diri_info)  
  4. {  
  5. listBox1.Items.Add(dir);  
  6.   
  7. }  
, And I tried to also get the files in a directory selected And display them in the listbox 2 and open selected file but files dosn't appear , how fix that please ?
  1. private void listBox2_SelectedIndexChanged(object sender, EventArgs e)  
  2. {  
  3.   
  4. DirectoryInfo dirictory_choisis =(DirectoryInfo)listBox1.SelectedItem;  
  5.   
  6. FileInfo[] files = dirictory_choisis.GetFiles();  
  7.   
  8.   
  9. foreach (FileInfo file in files)  
  10. {  
  11. listBox2.Items.Add(file.FullName);  
  12.   
  13. }  
  14. }  
  15. }  
  16. }  
[1]: https://i.stack.imgur.com/rmtZH.png

Answers (6)