Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.0   6.1   6.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3    Statistic  

Files.WriteFile

Writes a file with the given data.

Component: Files
Version: 3.5
Mac OS X: Yes
Windows: Yes
Server: Yes
FileMaker Cloud: Yes

MBS( "Files.WriteFile"; Data; FilePath { ; filter } )

Parameters

Parameter Description Example value
Data The data to save. Can be text or container. "Hello World"
FilePath The native file path. Something like "/Users/cs/desktop/test.txt" on Mac and "C:\Programs\Data\test.txt" on Windows. Files without path end in the root directory on Mac. "test.txt"
filter Optional
Can be base64 to decode text first from base64 encoding. Or can be Hex to decode from hex encoding.
"Base64"

Result

Returns "OK" or an error message.

Description

Writes a file with the given data.
You provide either a container value or some text. For text you can optionally define a filter like base64 or Hex.

See also Text.WriteTextFile for writing text files with specific encoding.

This function requires a native path. Use Path.FileMakerPathToNativePath to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use FileDialog functions.
For Server be aware that server has limited permissions and may not be able to access all files on a computer.

Examples

Write file with some text:

MBS("Files.WriteFile"; "Hello World"; $Path )

Write file with some text and decode base64:

MBS("Files.WriteFile"; "SGVsbG8gV29ybGQ="; "/Users/cs/Desktop/test.txt"; "base64")

Write container to temp file and launch:

# get temp folder
Set Variable [$TempFolder; Value:MBS( "Folders.SystemTemporary" )]
# and file name from container
Set Variable [$name; Value:MBS( "Path.LastPathComponent"; test::myContainer )]
# add name to folder path
Set Variable [$TempPath; Value:MBS( "Path.AddPathComponent"; $TempFolder; $name )]
# now write temp file
Set Variable [$r; Value:MBS( "Files.WriteFile"; test::myContainer; $TempPath)]
# and launch file
Set Variable [$r; Value:MBS( "Files.LaunchFile"; $TempPath)]

Write PDF to disk:

Set Variable [$path; Value:MBS( "Path.AddPathComponent"; MBS( "Folders.UserDesktop" ); Invoice::Invoice ID & ".pdf" )]
Set Variable [$r; Value:MBS("Files.WriteFile"; Invoice::PDF Output; $path)]

Write DynaPDF Library to disk and use it:

Set Variable [$path; Value:MBS( "Plugin.Path" )]
Set Variable [$folderpath; Value:MBS( "Path.RemoveLastPathComponent"; $path )]
Set Variable [$libPath; Value:MBS( "Path.AddPathComponent"; $folderpath; "dynapdf.dll" )]
Set Variable [$r; Value:MBS( "Files.WriteFile"; test2::DynaPDFContainer; $libPath )]
Set Variable [$r; Value:MBS( "DynaPDF.Initialize"; $libPath )]

See also

Example Databases


Files.Unmount   -   Folders.Applications

Feedback: Report problem or ask question.




Links
MBS FileMaker Plugins