Files.WriteFile
---------------

Writes a file with the given data.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Files](component_Files.md) | [3.5](newinversion35.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

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

**MBS**( **"Files.WriteFile";** /\* Writes a file with the given data. \*/  
**$Data**; /\* The data to save. Can be text or container.e.g. "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.e.g. "test.txt" \*/   
**$Filter**) /\* Optional; Can be base64 to decode text first from base64 encoding. Or can be Hex to decode from hex encoding.e.g. "Base64" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| 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 | Can be base64 to decode text first from base64 encoding. Or can be Hex to decode from hex encoding. | "Base64" | Optional |

### 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](TextWriteTextFile.md) for writing text files with specific encoding.  
  
See [FileDialog](component_FileDialog.md) functions if you like to show a save dialog to pick a destination for the file path.  
If you need to create directory first, please use [Files.CreateDirectory](FilesCreateDirectory.md) function.  
  
This function requires a native path. Use [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md) 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](component_FileDialog.md) 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](FoldersSystemTemporary.md)" )\]  
\# and file name from container   
Set Variable \[$name ; Value:MBS ( "[Path.LastPathComponent](PathLastPathComponent.md)"; test::myContainer )\]  
\# add name to folder path   
Set Variable \[$TempPath ; Value:MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; $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](FilesLaunchFile.md)"; $TempPath )\]  
Write PDF to disk:

 Set Variable \[$path ; Value:MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; MBS ( "[Folders.UserDesktop](FoldersUserDesktop.md)" ); Invoice::Invoice ID &amp; ".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](PluginPath.md)" )\]  
Set Variable \[$folderpath ; Value:MBS ( "[Path.RemoveLastPathComponent](PathRemoveLastPathComponent.md)"; $path )\]  
Set Variable \[$libPath ; Value:MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; $folderpath ; "dynapdf.dll" )\]  
Set Variable \[$r ; Value:MBS ( "Files.WriteFile"; test2::DynaPDFContainer ; $libPath )\]  
Set Variable \[$r ; Value:MBS ( "[DynaPDF.Initialize](DynaPDFInitialize.md)"; $libPath )\]  
### See also

- [Files.PrintFile](FilesPrintFile.md)
- [Files.ShareFile](FilesShareFile.md)
- [Folders.System](FoldersSystem.md)
- [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md)
- [Path.LastPathComponent](PathLastPathComponent.md)
- [Path.RemoveLastPathComponent](PathRemoveLastPathComponent.md)
- [Plugin.Path](PluginPath.md)
- [SQL.SetConnectionOption](SQLSetConnectionOption.md)
- [Text.WriteTextFile](TextWriteTextFile.md)
- [ZipFile.WriteFile](ZipFileWriteFile.md)

### Example Databases

- [CURL/Email/Email Parser and Preview](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/Email%20Parser%20and%20Preview.shtml#2ScriptAnchor_)
- [DynaPDF/Invoice/Invoice](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Invoice/Invoice.shtml#3ScriptAnchor_)
- [DynaPDF/Shrink PDF pages](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Shrink%20PDF%20pages.shtml#2ScriptAnchor_)
- [Files/WriteFile](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Files/WriteFile.shtml#2ScriptAnchor_)
- [SmartCard/SmartCard Signatures](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SmartCard/SmartCard%20Signatures.shtml#10ScriptAnchor_)

### Blog Entries

- [From speech to text with FileMaker and MBS](https://www.mbsplugins.de/archive/2025-05-01/From_speech_to_text_with_FileM/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Advent calendar - Door 17 - User Notifications](https://www.mbsplugins.de/archive/2024-12-17/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Advent calendar - Door 7 - Open Files With Roundabout Route Via Temporary Files](https://www.mbsplugins.de/archive/2024-12-07/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [Tips and tricks with MBS](https://www.mbsplugins.de/archive/2023-08-10/Tips_and_tricks_with_MBS/monkeybreadsoftware_blog_filemaker)
- [Neue Funktionen des MBS FileMaker Plugin 9.4](https://www.mbsplugins.de/archive/2019-10-05/Neue_Funktionen_des_MBS_FileMa/monkeybreadsoftware_blog_filemaker)
- [FileMaker 18 File Script Steps vs. BinaryFile functions](https://www.mbsplugins.de/archive/2019-06-03/FileMaker_18_File_Script_Steps/monkeybreadsoftware_blog_filemaker)
- [MBS Filemaker Plugin, version 3.5pr6](https://www.mbsplugins.de/archive/2013-11-15/MBS_Filemaker_Plugin_version_3/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 1/2022, Seite 28](https://filemaker-magazin.de/neuigkeit/4172-Appetithappen-FMM_202201)
- [Ausgabe 4/2020, Seite 34](https://filemaker-magazin.de/neuigkeit/4103-Appetithappen-FMM_202004)

This function is free to use.

Created 18th August 2014 , last changed 26th October 2023

  
[Files.Unmount](FilesUnmount.md) - [Folders.Applications](FoldersApplications.md)

[HTML Version](FilesWriteFile.shtml)