December 21, 2014
Hot Topics:

Working with the TextStream Object

  • March 7, 2002
  • By John Gosney
  • Send Email »
  • More Articles »

Reading from a Text File

Reading from a file is also very straightforward via the power of the TextStream object.  You can see how this is done with the following code, using the TextStream object's properties and methods.

<html>
<title>Working with the File Object</title>

<body>
<b>A second example of working with the File object!</b>

<hr>

<%
set TestFile=Server.CreateObject("Scripting.FileSystemObject")
set TFileStream=TestFile.OpenTextFile(
    "c:\inetpub\wwwroot\ASP_Examples\TestFile2.txt")
TextFormat=TFileStream.ReadLine

%>
<p>
<font face="Century Gothic" size="5" color="#008000">
<i>
<%=TextFormat%></i>
</font></p>

</body>
</html>

Opening this file in a Web browser, it should appear as it does here



Click here for larger image

The capability to read from an existing text file enables you to draw on all kinds of additional information resources when developing in ASP.

As you can see in this figure, the preceding code opens the TestFile2.txt file for reading. Then (through the power of the ReadLine method) the code reads the first line of text from this file, Welcome to the File Object in ASP!. Remember from the description of the ReadLine method, the data returned is set to a string. Keeping this in mind, you set the value of the ReadLine method to the variable TextFormat. Finally, before outputting the contents of this variable to the screen (via the line <%=TextFormat%>), you apply some general HTML formatting. I set the font to Century Gothic, assigned a bigger font size, and italicized it. This formatting gives the text (as read from the file) its unique appearance, as shown in the figure.


About the Authors

John Gosney is a Web-Database Applications Developer working with ColdFusion, Java, Active Server Pages, and other Web-based technologies. He has designed and implemented complete training courses for systems utilizing computer-based training. John Gosney is the author of several books including Customer Relationship Management Essentials and Web Enable Your Small Business In a Weekend.

This article is brought to you by Premier Press publisher of ASP Programming for the Absolute Beginner © Copyright Prima Publishing, All Rights Reserved

# # #





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel