APGen Documentation Previous Topic: Output.FlushBuffer() Next Topic: Output.Close() Parent Topic: Output Object    Output Object
Output.Open()
See Also:

The Output.Open() method opens a stream to an output file.

Syntax

VBScript:

Output.Open()

JScript:

Output.Open();

Notes

The output stream can be opened in one of two ways: By calling Output.Open(), or by setting the Output.StreamOutput.Open() is used more often than Output.Stream.   Output.Open() does not have to be explicitly called:  It is implicitly called when content is generated and no output stream is open.

Output.Open() opens or creates an output file.  It points the output stream (which can be retrieved from Output.Stream) to this file.  After Output.Open() is called, generated content is sent to the file.

Output object properties Filename, Dir, Path, Append, and CanCreateDirs specify how to open the output file.  The Path value specifies the path of the opened or created file.  See the other properties' documentation for more information on how they affect Output.Open().

If the output file does not exist, it is created.  If the file exists and Output.Append is False (the default), then it is overwritten.  If the output file exists and Output.Append is True, then the file is opened and any content that is generated is added to the end of the file.

Output.Open() is implicitly called when the following conditions are met:

  1. The output stream is closed.
  2. A content block containing non-whitespace characters, an  output expression, Output.Write() statement, or Output.BinaryWrite() statement is executed.

Output.Close() closes the output stream, which also closes the file.  Generating content after Output.Close() is called will trigger an implicit Output.Open() call.

If the Output.Buffer property is True when Output.Open() is called, and Output.Append is false, the opening/creation of the physical output file is delayed.  The buffer is created, but the physical output file is not opened until the first time the buffer is flushed.  It is often desirable to minimize the amount of time that an output file is open, thus eliminating the chance of a file being read when it is only partially generated - setting Output.Buffer to True accomplishes this.

Example

This example uses an explicit Output.Open() call to create an empty file.  The example also uses an (unnecessary) Output.Open() call to open another output file. 

<%#
Output.Filename = "empty.txt"
' This Output.Open call creates an empty file
Output.Open()

Output.Filename = "hello.txt"
' The following Output.Open() call is optional.
' The Output.Write statement would open the file
'   if Output.Open() weren't explicitly called.
Output.Open()
Output.Write "Hello World!"
#%>

Applies To

Output Object