469,943 Members | 2,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,943 developers. It's quick & easy.

save/open

I am trying to get the save/open dialog figured out. I am able open the save
dialog but when I put in a file name (whatever.txt) and save the file does
save with the name but it is blank. Below is what I have code so far.

Dim phonestreamwriter As StreamWriter
Dim responsedialogresults As DialogResult
SaveFileDialog1.InitialDirectory = Application.StartupPath
responsedialogresults = SaveFileDialog1.ShowDialog
If responsedialogresults <> DialogResult.Cancel Then
phonestreamwriter = New StreamWriter(SaveFileDialog1.FileName)
End If

Jul 21 '05 #1
3 1763
You open the StreamWriter which creates the file, but you also have to write
something to it. For example, if you added the following line after you
create the StreamWriter:

phonestreamwriter.WriteLine("Hello, world")
phonestreamwriter.Flush()
phonestreamwriter.Close()

the underlying file would have the content "Hello, world" inside the file.

You have to define what is supposed to go into the file. The save/open
dialog is only used to query the user for the file path.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

"Newbie" <Ne****@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
I am trying to get the save/open dialog figured out. I am able open the save dialog but when I put in a file name (whatever.txt) and save the file does
save with the name but it is blank. Below is what I have code so far.

Dim phonestreamwriter As StreamWriter
Dim responsedialogresults As DialogResult
SaveFileDialog1.InitialDirectory = Application.StartupPath
responsedialogresults = SaveFileDialog1.ShowDialog
If responsedialogresults <> DialogResult.Cancel Then
phonestreamwriter = New StreamWriter(SaveFileDialog1.FileName)
End If

Jul 21 '05 #2
If I have text in a rich text on a form how do I write that to the file

RichTextBox1.Text = SaveFileDialog1.FileName????

"Ben Lucas" wrote:
You open the StreamWriter which creates the file, but you also have to write
something to it. For example, if you added the following line after you
create the StreamWriter:

phonestreamwriter.WriteLine("Hello, world")
phonestreamwriter.Flush()
phonestreamwriter.Close()

the underlying file would have the content "Hello, world" inside the file.

You have to define what is supposed to go into the file. The save/open
dialog is only used to query the user for the file path.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

"Newbie" <Ne****@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
I am trying to get the save/open dialog figured out. I am able open the

save
dialog but when I put in a file name (whatever.txt) and save the file does
save with the name but it is blank. Below is what I have code so far.

Dim phonestreamwriter As StreamWriter
Dim responsedialogresults As DialogResult
SaveFileDialog1.InitialDirectory = Application.StartupPath
responsedialogresults = SaveFileDialog1.ShowDialog
If responsedialogresults <> DialogResult.Cancel Then
phonestreamwriter = New StreamWriter(SaveFileDialog1.FileName)
End If


Jul 21 '05 #3
phonestreamwriter.WriteLine(RichTextBox1.Text)

"Newbie" <Ne****@discussions.microsoft.com> wrote in message
news:D8**********************************@microsof t.com...
If I have text in a rich text on a form how do I write that to the file

RichTextBox1.Text = SaveFileDialog1.FileName????

"Ben Lucas" wrote:
You open the StreamWriter which creates the file, but you also have to write something to it. For example, if you added the following line after you
create the StreamWriter:

phonestreamwriter.WriteLine("Hello, world")
phonestreamwriter.Flush()
phonestreamwriter.Close()

the underlying file would have the content "Hello, world" inside the file.
You have to define what is supposed to go into the file. The save/open
dialog is only used to query the user for the file path.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

"Newbie" <Ne****@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
I am trying to get the save/open dialog figured out. I am able open the
save
dialog but when I put in a file name (whatever.txt) and save the file

does save with the name but it is blank. Below is what I have code so far.

Dim phonestreamwriter As StreamWriter
Dim responsedialogresults As DialogResult
SaveFileDialog1.InitialDirectory = Application.StartupPath
responsedialogresults = SaveFileDialog1.ShowDialog
If responsedialogresults <> DialogResult.Cancel Then
phonestreamwriter = New StreamWriter(SaveFileDialog1.FileName)
End If


Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Andras Gilicz | last post: by
4 posts views Thread by John | last post: by
reply views Thread by Dune | last post: by
6 posts views Thread by Mike | last post: by
4 posts views Thread by sunilj20 | last post: by
5 posts views Thread by Patrick | last post: by
3 posts views Thread by Newbie | last post: by
6 posts views Thread by Michael Groeger | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.