FileRead Function:
Read a text file.
Description:
The FileRead function allows the contents of a file to be read. The FileRead function has one required argument, pathname, which represents the complete path to an already existing file on the server. The FileRead function returns a string representing the contents of the file. ReadFile returns Null in the event of an error.
Syntax:
string = FileRead(pathname)
Example:
<%
'--- Writes the contents of File.txt in folder New Folder to the browser. Response.Write ReadFile(server.mappath("/New Folder/File.txt"))
'--- Writes the contents of File.txt in folder New Folder to a variable named a. dim a a = FileRead( server.mappath("/New Folder/File.txt"))
%>
ASP Source Code:
<%
Private Function FileRead(byVal pathname) dim objFSO, objFile, tmp On Error Resume Next Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(pathname, 1, False) tmp = objFile.ReadAll If Err Then FileRead = Null Else FileRead = tmp End If objFile.Close Set objFile = Nothing Set objFSO = Nothing On Error GoTo 0 End Function
%>
|