Read a text file in ASP.NET

The System.IO namespace contains the StreamReader class allow reading of files.
You can then read the entire contents of the text file into a string, by using ReadToEnd() method.
Remmber to close the StreamReader using the Close() method when finished.

 <!DOCTYPE html>

<script runat="server">

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sr As New System.IO.StreamReader(Server.MapPath("test.txt"))
        Dim sContent As String = sr.ReadToEnd
    End Sub


<html xmlns="">
<head id="Head1" runat="server">
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" Text="Button" />
Updated: June 30, 2020 — 9:16 pm