C# folderBrowserDialog + openFileDialog Hiding path on checkedListBox -


i have checkedlistbox; wich loads files inside folder; run/open when checked. i'm trying achieve load files inside listbox; without path.

i.e:

"c:\folder1\anotherfolder\myfile1.txt" 

in other words; want shown: filename (with or without extention).

i.e:

"myfile1.txt" 

the code i'm using:

//...     private string openfilename, foldername;     private bool fileopened = false; //...          openfiledialog ofd = new openfiledialog();         folderbrowserdialog fbd = new folderbrowserdialog();          if (!fileopened)         {             ofd.initialdirectory = fbd.selectedpath;             ofd.filename = null;               fbd.description = "please select *.txt folder";             fbd.rootfolder = system.environment.specialfolder.mycomputer;             if (fbd.showdialog() == system.windows.forms.dialogresult.ok)             {                 string foldername = fbd.selectedpath;                 foreach (string f in directory.getfiles(foldername))                 checkedlistbox1.items.add(f);             } 

i've tried several methods... folderbrowserdialog seems not possible. but, one, should work somehow (in theory) combining ofd fbd. cant figure out. since i'm quite "new" programming c#. idea if possible; or how done?

thanks in advance;

ricardo

you don't need openfiledialog @ all, change line adds files

checkedlistbox1.items.add(path.getfilename(f)); 

just remember add

using system.io; 

and can reduce 1 line code

checkedlistbox1.items.addrange(directory.getfiles(fbd.selectedpath).select(x => path.getfilename(x)).toarray()); 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -