Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP OpenAsTextStream Method

ASP OpenAsTextStream Method


File Object Reference Complete File Object Reference Manual


The OpenAsTextStream method opens a specified file and returns a TextStream object for accessing the file.

Syntax

FileObject.OpenAsTextStream(mode,format)

Parameters Description
mode Optional. How to open the file (input/output mode).
  • 1 = ForReading - Opens the file in read-only mode. You cannot write to this file.
  • 2 = ForWriting - Opens the file in read/write mode. If a file with the same name already exists, the old file is overwritten.
  • 8 = ForAppending - Opens the file and writes at the end of the file.
  • | | format | Optional. The format in which to open the file. If this argument is omitted, the file is opened in ASCII format. |

    Example

    <%

    dim fs,f,ts

    set fs=Server.CreateObject("Scripting.FileSystemObject")

    Set f=fs.GetFile("c:\test.txt")

    Set ts=f.OpenAsTextStream(ForWriting)

    ts.Write("Hello World!")

    ts.Close

    Set ts=f.OpenAsTextStream(ForReading)

    Response.Write(ts.ReadAll)

    ts.Close

    set ts=nothing

    set f=nothing

    set fs=nothing

    %>

    Output:

    Hello World!


    File Object Reference Complete File Object Reference Manual