Container.WriteFile
-------------------

Writes a file with the given container.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Container](component_Container.md) | [6.4](newinversion64.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Container.WriteFile"; Data; FilePath ) 

**MBS**( **"Container.WriteFile";** /\* Writes a file with the given container. \*/  
**$Data**; /\* The container field or value to save.e.g. $Image \*/   
**$FilePath**) /\* The native file path. Something like "/Users/cs/desktop/test.jpg" on Mac and "C:\\Programs\\Data\\test.jpg" on Windows. Files without path end in the root directory on Mac.e.g. "test.jpg" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| Data | The container field or value to save. | $Image |
| FilePath | The native file path. Something like "/Users/cs/desktop/test.jpg" on Mac and "C:\\Programs\\Data\\test.jpg" on Windows. Files without path end in the root directory on Mac. | "test.jpg" |

### Result

Returns OK or error.

### Description

Writes a file with the given container.  
See also [Files.WriteFile](FilesWriteFile.md) for more options.  
  
See [FileDialog](component_FileDialog.md) functions if you like to show a save dialog to pick a destination for the file path.  
You can use [Files.ReadFile](FilesReadFile.md) to read a file into a container field or variable.  
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

Read a file and write it elsewhere

 Set Variable \[$Image ; Value:MBS ( "[Container.ReadFile](ContainerReadFile.md)"; "/Users/cs/Pictures/Test.jpg")\]  
Set Variable \[$r ; Value:MBS ( "Container.WriteFile"; $Image ; "/Users/cs/Desktop/target.jpg")\]  
Export a container to desktop:

 # get path stored in the container field   
Set Variable \[ $ContainerPath ; Value: GetAsText ( Contacts::Photo Container ) \]   
\# get the file name portion   
Set Variable \[ $ContainerName ; Value: MBS ( "[Path.LastPathComponent](PathLastPathComponent.md)"; $ContainerPath ) \]   
\# take a folder on the computer, e.g. desktop   
Set Variable \[ $DesktopFolder ; Value: MBS ( "[Folders.UserDesktop](FoldersUserDesktop.md)" ) \]   
\# build path with file name on that folder   
Set Variable \[ $FilePath ; Value: MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; $DesktopFolder ; $ContainerName ) \]   
\# and export the content of container to that path   
Set Variable \[ $r ; Value: MBS ( "Container.WriteFile"; Contacts::Photo Container; $FilePath ) \]  
Write a HTML file and an image file to load in web viewer:

 Set Variable \[ $folder ; Value: MBS ( "[Folders.UserTemporary](FoldersUserTemporary.md)" ) \]   
Set Variable \[ $path ; Value: MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; $folder ; "test.jpg" ) \]   
Set Variable \[ $r ; Value: MBS ( "Container.WriteFile"; Images::Image ; $path ) \]   
\#   
Set Variable \[ $html ; Value: "&lt;html&gt;&lt;body&gt;&lt;p&gt;Hello World&lt;/p&gt;&lt;img src=test.jpg width=300&gt;&lt;/body&gt;&lt;/html&gt;" \]   
Set Variable \[ $path ; Value: MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; $folder ; "test.html" ) \]   
Set Variable \[ $r ; Value: MBS ( "[Text.WriteTextFile](TextWriteTextFile.md)"; $html ; $path ) \]   
\#   
Set Variable \[ $URL ; Value: MBS ( "[Path.FilePathToFileURL](PathFilePathToFileURL.md)"; $Path ) \]   
Set Web Viewer \[ Object Name: "web" ; URL: $URL \]  
### See also

- [Container.ReadFile](ContainerReadFile.md)
- [Container.WriteArchive](ContainerWriteArchive.md)
- [Path.FilePathToFileURL](PathFilePathToFileURL.md)
- [Path.LastPathComponent](PathLastPathComponent.md)
- [PDFKit.Combine](PDFKitCombine.md)
- [ScreenshotRect](ScreenshotRect.md)
- [SharingPanel.AddFilePath](SharingPanelAddFilePath.md)
- [SharingPanel.AddImageFile](SharingPanelAddImageFile.md)
- [SQL.GetFieldAsContainer](SQLGetFieldAsContainer.md)
- [Text.WriteTextFile](TextWriteTextFile.md)

### Example Databases

- [Containers/Create Container Preview](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Containers/Create%20Container%20Preview.shtml#1ScriptAnchor_)
- [CURL/Email/IMAP Email](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/IMAP%20Email.shtml#6ScriptAnchor_)
- [Drag and Drop/Better drag file from Container](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Drag%20and%20Drop/Better%20drag%20file%20from%20Container.shtml#2ScriptAnchor_)
- [DynaPDF/Place Picture](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Place%20Picture.shtml#1ScriptAnchor_)
- [DynaPDF/Signature Appearance](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Signature%20Appearance.shtml#1ScriptAnchor_)
- [Mac and iOS/MapKit/MapView BeeExample](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/MapKit/MapView%20BeeExample.shtml#6ScriptAnchor_)
- [Mac and iOS/MapKit/MapView](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/MapKit/MapView.shtml#8ScriptAnchor_)
- [Mac and iOS/PDFKit/PDFKit Print Documents](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/PDFKit/PDFKit%20Print%20Documents.shtml#4ScriptAnchor_)

### Blog Entries

- [FileMaker 2026 released](https://www.mbsplugins.de/archive/2026-06-10/FileMaker_2026_released/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin Advent calendar: 12 - Files](https://www.mbsplugins.de/archive/2023-12-12/MBS_Plugin_Advent_calendar_12_/monkeybreadsoftware_blog_filemaker)
- [Container](https://www.mbsplugins.de/archive/2022-10-20/Container/monkeybreadsoftware_blog_filemaker)
- [Convert Office Files in FileMaker](https://www.mbsplugins.de/archive/2022-07-04/Convert_Office_Files_in_FileMa/monkeybreadsoftware_blog_filemaker)
- [Query MBS Version from plugin in container](https://www.mbsplugins.de/archive/2021-04-19/Query_MBS_Version_from_plugin_/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)
- [Storing files for download on FileMaker Server with download URLs](https://www.mbsplugins.de/archive/2018-09-20/Storing_files_for_download_on_/monkeybreadsoftware_blog_filemaker)
- [LogicalDOC Webservice](https://www.mbsplugins.de/archive/2017-12-27/LogicalDOC_Webservice/monkeybreadsoftware_blog_filemaker)
- [Comparing Base Elements Plugin to MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2017-10-24/Comparing_Base_Elements_Plugin/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 6.4pr6](https://www.mbsplugins.de/archive/2016-09-07/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 2/2025, Seite 25](https://filemaker-magazin.de/neuigkeit/4286-Appetithappen-FMM_202502)
- [Ausgabe 6/2018, Seite 30 bis 31](https://filemaker-magazin.de/neuigkeit/4025-Appetithappen-FMM_201806)

This function is free to use.

Created 6th September 2016 , last changed 26th October 2023

  
[Container.WriteArchive](ContainerWriteArchive.md) - [ContinuityCamera.CanImport](ContinuityCameraCanImport.md)

[HTML Version](ContainerWriteFile.shtml)