Skip to main content

TrFile_ContentsDialog (function reference)

By June 1, 2024June 4th, 2024Online Help, Troi File Plug-in
Troi File Plug-in > Functions reference > TrFile_ContentsDialog
Troi File Plug-in for FileMaker Pro

TrFile_ContentsDialog

Shows the user a file selection dialog, the contents of the selected file is returned.
This function is a combination of “TrFile_SelectFileDialog” followed by a “TrFile_GetContents” function.

SyntaxFunction badge

TrFile_ContentsDialog ( switches ; { prompt ; { initialFolder } } )

Parameters

switches these alter the behavior of the function
prompt (optional) adds a prompt text to the GetFile Dialog. It may be left empty
initialFolder (optional) the path to the folder where the dialog initially starts

Switches

Switches can be empty or one of this:

-Encoding=Native (default)
-Encoding=UTF8
-Encoding=ASCII_DOS
-Encoding=ASCII_Windows
-Encoding=ASCII_Mac

This determines the character encoding of the text to be read.

You can also add this switch:

-ConvertToFMPLinebreaks this will convert any line breaks in the data to the line break FileMaker expects: CRLF, LF and CR will all become CR.

Returned Result

Data type returned

Text

Result

The characters of the file the user selected. If the user pressed cancel an error code “$$-1” is returned.

Originated in

Troi File Plug-in 1.0

Compatibility

FileMaker Pro 17 to FileMaker Pro 21 (2024)

Considerations

You can read up to 2 Gb into a field. However more than 500000 characters will slow down FileMaker considerably.

Only use -ConvertToFMPLinebreaks when getting text files, as it might change the data returned. If for example you use it with an image file the imported image might get corrupted.

On Mac the dialog will filter and show only text files by default. To change the default filtering use the TrFile_SetDefaultType function, or take a look at “Filtering Files” in the example databases.

Up to v5.0 there was an error in the documentation: it was incorrectly stated that UTF-8 was the default encoding. The default is -Encoding=Native, which is the current encoding as set in the system preference, for example on western Windows systems it usually is ISO_8859_1 or ASCII_Windows.

Example

Set Field [ result ; TrFile_ContentsDialog ( "-Unused" ;  
                          "Please select the text file you want to use:" ; "D:\DataFiles\" ) ]

You can also use a calculation for the prompt, for example this one which uses a global text field:

Set Field [ result ; TrFile_ContentsDialog ( "-Unused" ; 
                          "Please select the Excel file \"" & gFileName & "\"":" ) ]

This will result in a file selection dialog with this prompt text:
‘Please select the Excel file “invoices99.xls”:’.

Used in example file

DataIn.fmp12

Related functionsFunction badge

TrFile_GetContents
TrFile_SelectFileDialog

Related script stepScript step badge

Get File Contents with Dialog

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 17 to 2024 –> TrFile_ContentsDialog (filep4202) 2024-0604 19:21:32