Refer following program to Read a text file in ASP .NET.We have a textbox with textmode set to MultiLine and a button. On the click event of the button, we require to read the text file. The code within the Click event is shown below.
Code:
Sub WriteToFile(sender As Object, e As EventArgs)
Dim fp As StreamReader
Try
fp = File.OpenText(Server.MapPath(".Upload") & "test.txt")
txtMyFile.Text = fp.ReadToEnd()
lblStatus.Text = "File Succesfully Read!"
fp.Close()
Catch err As Exception
lblStatus.Text = "File Read Failed. Reason is as follows
" & err.ToString()
Finally
End Try
End Sub
Bookmarks