I once got taught how to append a text file ussing the following code, but how do I overwrite the file every time I press button one (nobody taught me that)?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ALPHAVAL As String = "C:\ALPHAVAL.txt"
If System.IO.File.Exists(ALPHAVAL) = True Then
Dim objWriter As New System.IO.StreamWriter(ALPHAVAL, True)
objWriter.WriteLine(TextBox1.Text)
objWriter.Close()
End If
End class
Signature of StreamWriter Constructor is this:
public StreamWriter(string path,bool append )
So Change your code :
System.IO.StreamWriter(ALPHAVAL, True)
to :
System.IO.StreamWriter(ALPHAVAL, False)
That tells StreamWriter to Overwrite the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With