Skip to main content
Version: 8.1

system.file.readFileAsString

This function is used in Python Scripting.

Description

Opens the file found at path filename, and reads the entire file. Returns the file as a string. Common things to do with this string would be to load it into the text property of a component, upload it to a database table, or save it to another file using system.file.writeFile function.

note

This function is scoped for Perspective Sessions, but since all scripts in Perspective run on the Gateway, the file must be located on the Gateway's file system.

Client Permission Restrictions

This scripting function has no Client Permission restrictions.

Syntax

system.file.readFileAsString(filepath, [encoding])

Parameters

TypeParameterDescription
StringfilepathThe path of the file to read.
StringencodingThe character encoding of the file to be read. Will throw an exception if the string does not represent a supported encoding. Common encodings are "UTF-8", "ISO-8859-1" and "US-ASCII". Default is your system's default. [optional]

Returns

String - The contents of the file as a string.

Scope

Gateway, Vision Client, Perspective Session

Code Examples

Example #1 - Reading File as String
# This code would prompt the user to choose a text file. If the user chooses a file, it would then set a text area on the screen to display the file.

path = system.file.openFile("txt")
if path != None:
contents = system.file.readFileAsString(path)
event.source.parent.getComponent("Text Area").text = contents

Keywords

system file readFileAsString, file.readFileAsString