M
mosscliffe
I have a simple form with a multiline Textbox.
I load the textbox with the contents of a text file.
I make changes to the textbox, then I attempt to OVERWRITE the original
file.
I have tried opening with FilMode.Create, FileMode.Truncate but they
bothh APPEND to the file.
What is the correct syntax for Overwriting - Thanks for any help
My Code is as follows:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strFname As String = DropDownList1.SelectedItem.Text
lblDebug.Text += "LoadButton: " &
DropDownList1.SelectedItem.Text & "<BR />"
Dim fw As New System.IO.StreamReader(Server.MapPath("MyData/" &
strFname), True)
TextBox1.Text = fw.ReadToEnd()
fw.Close()
fw.Dispose()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim strFname As String = DropDownList1.SelectedItem.Text
lblDebug.Text += "UpdateButton: " &
DropDownList1.SelectedItem.Text & "<BR />"
Dim fw As New System.IO.StreamWriter(Server.MapPath("MyData/" &
strFname), System.IO.FileMode.Create)
fw.Write(TextBox1.Text)
fw.Close()
fw.Dispose()
End Sub
I load the textbox with the contents of a text file.
I make changes to the textbox, then I attempt to OVERWRITE the original
file.
I have tried opening with FilMode.Create, FileMode.Truncate but they
bothh APPEND to the file.
What is the correct syntax for Overwriting - Thanks for any help
My Code is as follows:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strFname As String = DropDownList1.SelectedItem.Text
lblDebug.Text += "LoadButton: " &
DropDownList1.SelectedItem.Text & "<BR />"
Dim fw As New System.IO.StreamReader(Server.MapPath("MyData/" &
strFname), True)
TextBox1.Text = fw.ReadToEnd()
fw.Close()
fw.Dispose()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim strFname As String = DropDownList1.SelectedItem.Text
lblDebug.Text += "UpdateButton: " &
DropDownList1.SelectedItem.Text & "<BR />"
Dim fw As New System.IO.StreamWriter(Server.MapPath("MyData/" &
strFname), System.IO.FileMode.Create)
fw.Write(TextBox1.Text)
fw.Close()
fw.Dispose()
End Sub