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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -