<%@ Page Language="vb" Explicit="true" Strict="true" %>
<%@ Import Namespace = "System.IO" %>
<script language="vb" runat="Server">
Sub ReadFile(ByVal sender As Object, ByVal e As EventArgs)
Dim FileStreamReader As StreamReader
Try
FileStreamReader = File.OpenText(Server.MapPath(".\Upload\") & "test.txt")
TextContent.Text = FileStreamReader.ReadToEnd()
FileStreamReader.Close()
OutputLabel.Text = "File Succesfully Read!"
Catch exc As Exception
OutputLabel.Text = "Error in Reading file. Error is " & exc.ToString()
Finally
If Not FileStreamReader Is Nothing Then
FileStreamReader.Close()
End If
End Try
End Sub
</script>
<html>
<head>
<title>Opening a File</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:TextBox ID="TextContent" Runat="server" TextMode="MultiLine" Rows="10" Columns="75"></asp:TextBox><br>
<asp:Button ID="Submit" Runat="server" Text="Submit" OnClick="ReadFile"></asp:Button>
<asp:Label ID="OutputLabel" Runat="server"></asp:Label>
</form>
</body>
</html>
|