Click here to Skip to main content
16,017,745 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
HI guys,

I have a question here.

The situation is:
I use OpenFileDialogue to select some files (e.g TextOne.txt,TextTwo.txt, TextThree.txt).
Now I want to access send the TextTwo.txt to a stream object to be read.
How to do that?
Because;
C#
stream = OpenFileDialog.OpenFile();

is getting the TextOne.txt.

C++
FileNames[i]
or
C++
FileName[i]
just returns the string but not the stream.


Need help on this?
Posted

1 solution

OpenFileDialog always returns only the file name: It can't return the stream because it does not know what you are going to do with it: Open it as text or binary.
If you are using it with
this.openFileDialog1.Multiselect = true;
Then you need to loop through all names and open them yourself:
C#
foreach (String file in openFileDialog1.FileNames)
   {
   FileStream fileStream = new FileStream(file, FileMode.Open);

   ... // Do something with the stream.

   }
 
Share this answer
 
Comments
Olivier Levrey 22-Feb-11 4:02am    
Voted 5. Perfect answer.
Sergey Alexandrovich Kryukov 22-Feb-11 4:13am    
Correct, 5.
--SA
skunkhead 28-Feb-11 22:55pm    
thanks :)

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