Working with the TextStream Object

The TextStream object is the heart of most of the file manipulation in ASP 3.0. Check out this article to see the TextStream object in action.

provided by: 
Originally published at Internet.com


This article is brought to you by Premier Press
publisher of John Gosney's ASP Programming for the Absolute Beginner.

Working with the TextStream Object

The TextStream object is the heart of most of the file manipulation in ASP 3.0. There are three specific methods within the TextStream object: CreateTextFile, OpenTextFile, and OpenAsTextStream. The TextStream object has its own set of properties and methods. First, the properties: * AtEndOfLine. Returns a value of True if the file pointer (the location of the response as the file is read) is at the end of a line in the file * AtEndOfStream. Returns a value of True if the file pointer is at the end of the file * Column. Depending on the current character being read within the file, returns the column number of this character, starting from 1 * Line. Depending on the current line number being read within the file, returns this line number, starting from 1 And now, the methods of the TextStream object: * Close. Closes an open file. * Read (a number). Reads a specific number of characters from the file. For example, Read(20) reads the first 20 characters within the file being examined. * ReadAll(). Reads the entire file and places it within a text string. * ReadLine(). Reads a single line from the file and places it within a text string. * Skip (a number). Skips over a specific set of characters from the file being examined. * SkipLine. Skips a line when reading from the file being examined. * Write (a string). Writes a specified string to the file being examined. * WriteLine (a string). Writes a string to the file being examined and then writes a newline character within the file. * WriteBlankLines(a number). Writes the specified number of blank lines to the file being examined. The following is an example of the TextStream object in action. Note the location of where you create the file will vary (as well as the name of the actual text file: in this example, it is called "Test2File.txt"), depending on your particular server configuration. Working with the File Object An example of working with the File object!
<% set TestFile=Server.CreateObject("Scripting.FileSystemObject") set TFileStream= TestFile.CreateTextFile( "c:\inetpub\wwwroot\ASP_Examples\Test2File.txt") TFileStream.WriteLine "Welcome to the File Object in ASP!" TFileStream.WriteBlankLines(3) TFileStream.WriteLine "Between this line and the opening line are three blank lines. These blank lines were inserted using the WriteLine method of the TextStream object. Now, let's write three more blank lines before the next section of text is inserted." TFileStream.WriteBlankLines(3) TFileStream.WriteLine "Okay, that's better-three more blank lines have just been inserted! I think you probably get the idea of how to use the WriteLine method, so let's move on to more interesting things." TFileStream.Close %> After the page loads, the Test2File.txt file is created. Navigate to the location of this file - it should look something like this (all the text you asked to be inserted, including the blank lines is included within this file)...

Read article at Internet.com site
Related Articles
- Understanding New JScript .NET Statements
JScript .NET is a fully object oriented programming language with some great new features. In this article learn about some of the new key statements in the JScript .NET language including class, const, enum, package, and import.
- Aspect-Oriented Programming
- New JScript .NET Data Types
- ADO is AOK (a simple ADO tutorial)
- Implementing Custom Attributes in .NET
- Introducing the .NET Framework and JScript .NET
- Passing and Reading URL Parameters
- Working with a Timer in C#
- So You Want Interactive Form Elements, Huh?
- What is C#?
Regional Articles
- Working with the TextStream Object Alabama
- Working with the TextStream Object Alaska
- Working with the TextStream Object Arizona
- Working with the TextStream Object Arkansas
- Working with the TextStream Object California
- Working with the TextStream Object Colorado
- Working with the TextStream Object Connecticut
- Working with the TextStream Object DC
- Working with the TextStream Object Delaware
- Working with the TextStream Object Florida
- Working with the TextStream Object Georgia
- Working with the TextStream Object Hawaii
- Working with the TextStream Object Idaho
- Working with the TextStream Object Illinois
- Working with the TextStream Object Indiana
- Working with the TextStream Object Iowa
- Working with the TextStream Object Kansas
- Working with the TextStream Object Kentucky
- Working with the TextStream Object Louisiana
- Working with the TextStream Object Maine
- Working with the TextStream Object Maryland
- Working with the TextStream Object Massachusetts
- Working with the TextStream Object Michigan
- Working with the TextStream Object Minnesota
- Working with the TextStream Object Mississippi
- Working with the TextStream Object Missouri
- Working with the TextStream Object Montana
- Working with the TextStream Object Nebraska
- Working with the TextStream Object Nevada
- Working with the TextStream Object New Hampshire
- Working with the TextStream Object New Jersey
- Working with the TextStream Object New Mexico
- Working with the TextStream Object New York
- Working with the TextStream Object North Carolina
- Working with the TextStream Object North Dakota
- Working with the TextStream Object Ohio
- Working with the TextStream Object Oklahoma
- Working with the TextStream Object Oregon
- Working with the TextStream Object Pennsylvania
- Working with the TextStream Object Rhode Island
- Working with the TextStream Object South Carolina
- Working with the TextStream Object South Dakota
- Working with the TextStream Object Tennessee
- Working with the TextStream Object Texas
- Working with the TextStream Object Utah
- Working with the TextStream Object Vermont
- Working with the TextStream Object Virginia
- Working with the TextStream Object Washington
- Working with the TextStream Object West Virginia
- Working with the TextStream Object Wisconsin
- Working with the TextStream Object Wyoming
Related Articles
- Understanding New JScript .NET Statements
JScript .NET is a fully object oriented programming language with some great new features. In this article learn about some of the new key statements in the JScript .NET language including class, const, enum, package, and import.
- Aspect-Oriented Programming
- New JScript .NET Data Types
- ADO is AOK (a simple ADO tutorial)
- Implementing Custom Attributes in .NET
- Introducing the .NET Framework and JScript .NET
- Passing and Reading URL Parameters
- Working with a Timer in C#
- So You Want Interactive Form Elements, Huh?
- What is C#?

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML