leearach2004
Technical User
Hi there ive just started to play around with using data in text files.
Have have got the view data in a text file working in the OnPage_Load Routine but I have a button to update the text file with the code to write information to the file.
The problem I have is the first time you click the button nothing happens, but then every time after that it works fine.
This is the basic test code i am using for this
sub Page_Load(sender as Object, e as EventArgs)
'Open a file for reading
Dim FILENAME as String = Server.MapPath("test.txt")
'Get a StreamReader class that can be used to read the file
Dim objStreamReader as StreamReader
objStreamReader = File.OpenText(FILENAME)
'Now, read the entire file into a string
Dim contents as String = objStreamReader.ReadToEnd()
'Set the text of the file to a Web control
TextBox2.Text = contents
objStreamReader.Close()
end sub
Sub btnupd_Click(sender As Object, e As EventArgs)
'Open a file for reading
Dim FILENAME as String = Server.MapPath("test.txt")
'Get a StreamReader class that can be used to read the file
Dim objStreamWriter as StreamWriter
objStreamWriter = File.AppendText(FILENAME)
'Now, write the contents of textbox1 to text file
objStreamWriter.Write(vbCrLf)
objStreamWriter.Write(TextBox1.Text)
'Close the stream
objStreamWriter.Close()
End Sub
I just dont understand why it wont work on first click but will evertimne after
hope somone can help
lee
Have have got the view data in a text file working in the OnPage_Load Routine but I have a button to update the text file with the code to write information to the file.
The problem I have is the first time you click the button nothing happens, but then every time after that it works fine.
This is the basic test code i am using for this
sub Page_Load(sender as Object, e as EventArgs)
'Open a file for reading
Dim FILENAME as String = Server.MapPath("test.txt")
'Get a StreamReader class that can be used to read the file
Dim objStreamReader as StreamReader
objStreamReader = File.OpenText(FILENAME)
'Now, read the entire file into a string
Dim contents as String = objStreamReader.ReadToEnd()
'Set the text of the file to a Web control
TextBox2.Text = contents
objStreamReader.Close()
end sub
Sub btnupd_Click(sender As Object, e As EventArgs)
'Open a file for reading
Dim FILENAME as String = Server.MapPath("test.txt")
'Get a StreamReader class that can be used to read the file
Dim objStreamWriter as StreamWriter
objStreamWriter = File.AppendText(FILENAME)
'Now, write the contents of textbox1 to text file
objStreamWriter.Write(vbCrLf)
objStreamWriter.Write(TextBox1.Text)
'Close the stream
objStreamWriter.Close()
End Sub
I just dont understand why it wont work on first click but will evertimne after
hope somone can help
lee