Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Am struggling in open the selected file and directory listed on listbox.

Actually, I have designed the listbox which list all files and directory present on C drive.
Now a button click which has to open the selected file or directory using c#.
Please advice.
Posted
Comments
Richard C Bishop 4-Jun-14 18:14pm    
Where are you stuck? What have you tried?
[no name] 4-Jun-14 18:41pm    
Use the Process class like you already know how to use. What is the actual problem?
Sergey Alexandrovich Kryukov 4-Jun-14 19:09pm    
You can open a file, but there is no such notion as "open a directory".
As to opening the file, the answer depends on what you are going to do with it. There is no just "open". Open for what operation, with what options?
—SA

1) you can get all drivers like this:

string[] drivers = Directory.GetLogicalDrives();

2)you can file your list box:
string[] dir = Directory.GetFiles(string path);
string [] files= Directory.GetDirectories(string path);

now you can use in this:
-fileInfo
-directoryInfo

string[] dir = Directory.GetFiles("c:/");
DirectoryInfo dInfo = new DirectoryInfo("c:/");
FileInfo[] fInfo= dInfo.GetFiles();

- alot more prop:

fInfo[0].Name;
fInfo[0].DirectoryName;
fInfo[0].LastWriteTime;

3) and then you can fill the list boxs in the files or folder name
and use the name file to Navigate in files
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Jun-14 22:56pm    
By some reason, you are trying to answer previous OP's question. Didn't you mix them up?
—SA
Unfortunately, your question is based on some misconceptions on what file systems do (actually, as well as your previous question). Please see my comments to the question.

Several different classes and methods are involved, depending on what you are going to do with the file. First of all, System.IO.File:
http://msdn.microsoft.com/en-us/library/system.io.file.aspx[^].

Now, opening a file at the level of System.IO.StreamReader, System.IO.StreamWriter, or System.IO.BinaryReader. These classes are most practical and robust in use. Please see:
http://msdn.microsoft.com/en-us/library/vstudio/system.io.streamreader[^],
http://msdn.microsoft.com/en-us/library/vstudio/system.io.streamwriter[^],
http://msdn.microsoft.com/en-us/library/vstudio/system.io.binaryreader[^],
http://msdn.microsoft.com/en-us/library/vstudio/system.io.binarywriter[^].

And also you can open the file with the System.IO.FileStream:
http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx[^].

I am not sure it can help you, unless you finally learn what file systems do and get the basic concepts. It's hard to help someone who is aiming to "open" a directory. Perhaps, you misconception is related to your observation of some software application which "open" the directory visually, but it's very important to sort out UI from what happens behind it.

—SA
 
Share this answer
 
v3

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