Click here to Skip to main content
15,887,290 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to make a program that lists all the files in my computer into a listbox. I want to make a easy and fast to use file browser that allows you to open and run files from there. Thanks.
Posted

1 solution

For File browser you need two thing

1. Directory path (Directory which user selects)
2. List of all file.

for 1. Requirement you can use FileBrowser,
and for 2.
you have to add list box and load all file list in the below code will help

C#
//Here "c:\user\public\picture" is Directory path It can be any path form harddrive
string[] filePaths = Directory.GetFiles(@"c:\user\public\picture");
foreach (string m in filePaths)
{
    ListViewItem liv = new ListViewItem(m);
    listView1.Items.Add(liv);
}


All the Best
 
Share this answer
 
v2
Comments
MR. AngelMendez 4-Jun-12 2:11am    
Hi, thanks for the help but I am running into a little problem. it is giving me an error on each of the "\" symbols. what can I do to fix this? thanks.
lukeer 4-Jun-12 2:37am    
Because the given path is an example. In your application, you wouldn't hard-code any path.
If, for the example, you want to do that, you will have to use forward slashes ("/"), double-backslashes ("\\") or an @ just before the path string: GetFiles(@"c:\whatever").
MR. AngelMendez 4-Jun-12 3:12am    
thanks
MR. AngelMendez 4-Jun-12 3:10am    
never mind I got it, I'm supposed to use "\\" thanks for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900