openfiledailog

J

Jay

First I want to say thanks for the help on my previous post. I got the save
to work. But now I am working on the open and when I open a file it comes
up blank in my rich text box and then I go and look at the file it to is
blank. I tried to use the help file and no matter what I do it comes up
blank. This is what I have left, what am I missing here? BTW this code is
straight from the help file.

If openFileDialog1.ShowDialog() = DialogResult.OK Then

openstreamwriter = New StreamWriter(openFileDialog1.FileName)

If Not (myStream Is Nothing) Then

' Insert code to read the stream here.

myStream.Close()

End If

End If
 
M

Morten Wennevik

Hi Jay,

A StreamWriter writes data to a stream/file. If you want to read the file, use a StreamReader.
 
M

Morten Wennevik

Jay,

If you have a file called MyFile.txt
and a RichTextBox called rtb you would typically do something like.

C# code but it shouldn't be hard to translate to VB

StreamReader sr = new StreamReader("C:\\MyFile.txt");
rtb.Text = sr.ReadToEnd();
sr.Close();

Using a OpenFileDialog you could do something like.

if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader sr = new StreamReader(openFileDialog1.FileName);
rtb = sr.ReadToEnd();
sr.Close();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top