Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macros

Macro Debugging

How To

Using variables

Finding and modifying objects

Creating new page content

Asking for user input

Storing persistent data

Using binary data

Sorting objects

Macro menus

Bulleted and numbered lists

Accessing the file system

Sample Macros

Concepts

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Last updated on: February 02, 2025
Also available as a single HTML file

Onetastic Macro Documentation > Functions > File System Functions > FileSystem_ReadFromFile

FileSystem_ReadFromFile

Reads the contents of the given file in either binary or text mode. If binary mode is used, return type is Binary, otherwise return type is String.

Syntax

Binary|String FileSystem_ReadFromFile(
	File|String file, 
	String mode)

Parameters

File|String file
File to read from. This can either be a File object or a String that contains the full path to the file.
String mode
Read mode that indicates binary read or the text encoding of the file. Possible values are: binary, text, utf8, utf16.

Remarks

See below for the how the file content is read based on the "mode" parameter:
Value of mode Content is read as Text encoding Return type
binary binary N/A Binary
text text Auto detected as either UTF-8 or UTF-16 String
utf8 UTF-8
utf16 UTF-16

Examples

// Show the file picker to pick an existing file $files = FileSystem_ShowOpenFileDialog(false) // Read the contents if (Array_Length($files) > 0) $text = FileSystem_ReadFromFile($files[0], "text") // Read an image and insert into the current page $binary = FileSystem_ReadFromFile("c:\\temp\\image.png", "binary") $image = InsertObject(GetCurrentPage(), "Image", -1) $image.data = $binary

Reference

Statements

Hierarchy Objects

Page Objects

Other Objects

Functions

Array Functions

Color Functions

Data Store Functions

Date/Time Functions

Dialog Box Functions

File System Functions

Macro Execution Functions

Macro Menu Functions

Object Functions

Special Functions

String Functions

Window Functions