Xbasic

GET_FROM_FILE Function

Syntax

Result as C = get_from_file(C fileLocation [,L flagBase64Encode])

Arguments

filenameCharacter

The fully qualified file path and name on the local machine, the URL of a remote file, or a JSON string defining the following properties:

connectionStringCharacter

The name of a saved Storage Connection.

objectNameCharacter

The name of the file object to read.

flagBase64EncodeLogical

Default = .f.. If .t., Base64 encodes the data before returning it.

Returns

ResultCharacter

Returns the file contents. If the operation fails, returns an empty string.

Description

Returns the contents of a file as a text string.

Discussion

GET_FROM_FILE() opens a file specified by filename and reads the contents of the file. Returns a character string with the contents of the file.

Example: Reading a file

This script reads the contents of a file.

dim fileLocation as C = A5.GET_PATH() + "simpleExample.txt"
dim fileContents as C = get_from_file(fileLocation)

Example: Reading a file from a URL

This script reads the contents of a file located at a URL.

dim fileLocation as C = "https://www.example.com/simpleExample.txt"

dim fileContents as C = get_from_file(fileLocation)

Example: Reading a file from AmazonS3

This script reads the contents of a file from AmazonS3.

dim fileReadParams as P
fileReadParams.connectionString = "AmazonS3" 'The name of a saved Storage Connection string
fileReadParams.objectName = "logs\myFile.txt" 'The name of the object to read

' Generate a JSON string:
dim containsSpecialFlags as L = .f.
dim compactJSON as L = .t.

dim fileLocation as C = json_generate(fileReadParams,containsSpecialFlags,compactJSON)

dim fileContents as C = get_from_file(fileLocation)

See Also