By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

form won't save...?

P: n/a
Hello,
I have the simple code below to save text, but when I click the save btn
the form creates the file in the C drive, but it would not save what's in the
text box.

Dim sw As New IO.StreamWriter("C:\SomeFile.txt", True)
sw.WriteLine(txt1.Text)

any suggestions on why it's not saving be great.
thanks for your help...
Nov 4 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Karim,

The fact is that you are not closing the streamreader, that is implicitely
done by this code.
\\\
Using sw As New IO.StreamWriter("C:\SomeFile.txt", True)
sw.WriteLine(txt1.Text)
End Using
///

Cor

"karim" <ka***@discussions.microsoft.comschreef in bericht
news:C2**********************************@microsof t.com...
Hello,
I have the simple code below to save text, but when I click the save
btn
the form creates the file in the C drive, but it would not save what's in
the
text box.

Dim sw As New IO.StreamWriter("C:\SomeFile.txt", True)
sw.WriteLine(txt1.Text)

any suggestions on why it's not saving be great.
thanks for your help...

Nov 4 '08 #2

P: n/a
"karim" <ka***@discussions.microsoft.comschrieb:
I have the simple code below to save text, but when I click the save
btn
the form creates the file in the C drive, but it would not save what's in
the
text box.

Dim sw As New IO.StreamWriter("C:\SomeFile.txt", True)
sw.WriteLine(txt1.Text)

any suggestions on why it's not saving be great.
thanks for your help...
The stream writer uses a buffer. You can either flush the buffer by calling
its 'Flush' method or by setting the 'AutoFlush' property. Closing the
stream writer will flush the buffer and persist the text to disk too (see
Cor's reply).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 4 '08 #3

P: n/a
On Nov 4, 8:33*am, karim <ka...@discussions.microsoft.comwrote:
Hello,
* * I have the simple code below to save text, but when I click the save btn
the form creates the file in the C drive, but it would not save what's inthe
text box.

Dim sw As New IO.StreamWriter("C:\SomeFile.txt", True)
* * * * sw.WriteLine(txt1.Text)

any suggestions on why it's not saving be great.
thanks for your help...
Hi Karim,
As you can use StreamWriter with Using statement, you can shorten your
code by directly calling WriteAllText method as an alternative under
My namespace.

My.Computer.FileSystem.WriteAllText("C:\SomeFile.t xt", _
txt1.Text, True)

http://msdn.microsoft.com/en-us/libr...xs(VS.80).aspx

Also aware that UTF-8 is default in that method unless you specify
other encoding as 4th argument.

Hope this helps,

Onur Güzel
Nov 5 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.