Asp Codes
ActiveX
ADO
Array
Code Snippets
Components
Data Access
Date Time
Files
Graphics
HTML Formatting
Mathematics
Miscellaneous
Sessions
SQL
Strings
Techniques
XML
Asp.Net > Code Snippets sample source codes
Read a file
Read a file <%@ Import Namespace="System.IO" %> <script language="vb" runat="server"> sub Page_Load(sender as Object, e as EventArgs) 'Open the sampletext.txt file . Note this is in the same directory as the script Dim testfile as String = Server.MapPath("sampletext.txt") 'Create a streamreader class Dim objStreamReader as StreamReader 'open the file objStreamReader = File.OpenText(testfile) 'Read the file storing it in the readfile string Dim readfile as String = objStreamReader.ReadToEnd() 'Place the string into a web control lblTextFile.Text = readfile 'close the StreamReader class objStreamReader.Close() end sub </script> <asp:label runat="server" id="lblTextFile" />
Privacy Policy
|
Link to Us
|
Links