K
kimiraikkonen
Hello,
Here's a very annoying problem that i couldn't make out. The problem
is that: I open a text file using "streamreader" with no problem then
when i save my existing txt file using streamWriter, sometimes it
works very well, but sometimes it doesn't save and overwrite existing
file. (Texbox1.text is main text area.)
The problem doesn't occur sometimes but it really hurts. You click
save button and exit. Sometimes changes have been saved successfully
(re-open and see with Windows Notepad), but sometimes nothing has been
saved. That's really cruel. :-(
Here is streamwriter code:
Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SaveAsToolStripMenuItem.Click
Dim Save As New SaveFileDialog()
Dim myStreamWriter As System.IO.StreamWriter
Save.Filter = "Plain Text Files (*.txt)|*.txt|All files (*.*)|
*.*"
Save.CheckPathExists = True
Save.Title = "Save"
Save.ShowDialog(Me)
Try
myStreamWriter = System.IO.File.CreateText(Save.FileName)
myStreamWriter.Write(TextBox1.Text)
myStreamWriter.Flush()
Catch ex As Exception
' Do nothing on Exception
End Try
End Sub
What's wrong here? Note that, when the fake-save problem occurs, if i
re-save file with several retries without closing my project, then it
gets saved.
Regards.
Here's a very annoying problem that i couldn't make out. The problem
is that: I open a text file using "streamreader" with no problem then
when i save my existing txt file using streamWriter, sometimes it
works very well, but sometimes it doesn't save and overwrite existing
file. (Texbox1.text is main text area.)
The problem doesn't occur sometimes but it really hurts. You click
save button and exit. Sometimes changes have been saved successfully
(re-open and see with Windows Notepad), but sometimes nothing has been
saved. That's really cruel. :-(
Here is streamwriter code:
Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SaveAsToolStripMenuItem.Click
Dim Save As New SaveFileDialog()
Dim myStreamWriter As System.IO.StreamWriter
Save.Filter = "Plain Text Files (*.txt)|*.txt|All files (*.*)|
*.*"
Save.CheckPathExists = True
Save.Title = "Save"
Save.ShowDialog(Me)
Try
myStreamWriter = System.IO.File.CreateText(Save.FileName)
myStreamWriter.Write(TextBox1.Text)
myStreamWriter.Flush()
Catch ex As Exception
' Do nothing on Exception
End Try
End Sub
What's wrong here? Note that, when the fake-save problem occurs, if i
re-save file with several retries without closing my project, then it
gets saved.
Regards.