how to display files of a folder in listbox by browsing the folder using asp.net -
string path = textbox1.text; directoryinfo dtr = new directoryinfo(path); if (dtr.exists) { fileinfo[] files = dtr.getfiles("*.txt"); foreach (fileinfo file in files) { listbox1.items.add(file.name); } label1.text = "entered listbox"; } else { label1.text = "directory doesnt exit"; }
i using asp.net, have textbox,a button , listbox, copying path of folder in textbox , on button click display text file in listbox..... but, dont want copy folder path textbox rather want browse folder on button click , display path in textbox , on button click display files inside particular folder
replace
listbox1.items.add(file.name);
with
listbox1.items.add(file.name.substring(file.name.lastindexof('\\')));
Comments
Post a Comment