GetSaveFolderItem

From Xojo Documentation


Method

Used to present the standard Save As dialog box to the user.

Syntax

result=GetSaveFolderItem(filter, default file name)

Part Type Description
result FolderItem Represents the file the user wants to create.
filter String The file type to be assigned to the file, as defined in the File Type Sets Editor or via the FileType class.
default file name String The name that should appear by default in the Save As dialog box.

Notes

The GetSaveFolderItem function displays the standard Save As file dialog box, allowing the user to choose a location and enter a name for the file to be saved. The SaveAsDialog class provides the same functionality but allows for customization.

The GetSaveFolderItem function does not create the file. It simply returns a FolderItem that represents the potential file. To create the actual file, you will need to call or Create shared method for TextOutputStream or the Create shared method of the BinaryStream.

The filter should either be an empty string or the name of a file type as defined in the File Type Sets Editor or via the FileType class.

On macOS, a Hide Filename Extension checkbox appears in the save-file dialog. The FolderItem returned has its ExtensionVisible property set according to the user's use of this checkbox.

Examples

This example displays the save as file dialog box. The File Type referred to by GetSaveFolderItem declares the common file type "text/plain", which you will first want to add to your project using the File Type Sets Editor.

A text file is then created and the text properties of three TextFields are written to the new file. Finally the file is closed.

Dim f As FolderItem
Dim fileStream As TextOutputStream
f = GetSaveFolderItem(FileTypes1.Text, "MyInfo")
If f <> Nil Then
fileStream = TextOutputStream.Create(f)
fileStream.WriteLine(NameField.Text)
fileStream.WriteLine(AddressField.Text)
fileStream.WriteLine(PhoneField.Text)
fileStream.Close
End If

See Also

GetOpenFolderItem, SelectFolder functions; FileType, FolderItem, FolderItemDialog, SaveAsDialog classes.