SaveAsDialog

From Xojo Documentation

Class (inherits from FolderItemDialog)

Used to create customized Save As dialogs. Non-customizable Save As dialogs are created by the GetSaveFolderItem function.

Properties
ActionButtonCaption Left Title
CancelButtonCaption PromptText Top
Filter Result fa-lock-32.png
InitialDirectory SuggestedFileName


Methods
ShowModal ShowModalWithin

Notes

Using the properties of the FolderItemDialog class, you can customize the following aspects of a save-file dialog box:

  • Position (Left and Top properties)
  • Default directory (Initial Directory property)
  • Valid file types to show (Filter property).
  • If you specify more than one file type (separate the file type names with semicolons), SaveAsDialog will add a Format pop-up menu to the dialog, allowing the user to specify the desired file type to use. Examine the extension of the file name returned to see which format was chosen.
  • Default filename (SuggestedFileName property)
  • Text of the Validate and Cancel buttons (ActionButtonCaption and CancelButtonCaption properties)
  • Text that appears in the Title bar of the dialog (Title property)
  • Text that appears in the body of the dialog (PromptText property)

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.

Sample Code

The following code opens a customized save-file dialog box and displays the contents of the "Documents" directory in the browser area. It refers to the 'text/plain' common file type defined in the FileTypes1 file type set.

Dim dlg As New SaveAsDialog
Dim f As FolderItem
dlg.InitialDirectory = SpecialFolder.Documents
dlg.PromptText = "Prompt Text"
dlg.SuggestedFileName = "Suggested Filename"
dlg.Title = "Title Property"
dlg.Filter = FileTypes1.Text // defined as a file type in FileTypes1 file type set
f = dlg.ShowModal
If f <> Nil Then
// file saved
Else
// user canceled
End If

The following code creates a pop-up menu in the Save As dialog that gives the user the option of choosing among four file types.

Dim dlg As New SaveAsDialog
Dim f As FolderItem

Dim txtType As New FileType
txtType.Name = "Text File (*.txt)"
txtType.MacType = "TEXT"
txtType.Extensions = "txt"

Dim htmlType As New FileType
htmlType.Name = "HTML File (*.htm, *.html)"
htmlType.MacType = "HTML "
htmlType.Extensions = "htm"

Dim csvType As New FileType
csvType.Name = "CSV File (*.csv)"
csvType.MacType = "TEXT"
csvType.Extensions = "csv"

Dim xlsType As New FileType
xlsType.Name = "Excel File (*.xls)"
xlsType.MacType = "XLS "
xlsType.Extensions = "xls"

dlg.InitialDirectory = SpecialFolder.Desktop
dlg.promptText = "Prompt Text"
dlg.SuggestedFileName = "Suggested Filename"
dlg.Title = "Title Property"
dlg.Filter = txtType + htmlType + csvType + xlsType
f = dlg.ShowModal
If f <> Nil Then
If Right(f.Name, 3) = "txt" Then
MsgBox("1")
ElseIf Right(f.Name, 3) = "htm" Then
MsgBox("2")
ElseIf Right(f.Name, 3) = "csv" Then
MsgBox("3")
ElseIf Right(f.Name, 3) = "xls" Then
MsgBox("4")
End If
Else
// user canceled
End If

See Also

FileType, FolderItem, FolderItemDialog, OpenDialog, SelectFolderDialog classes; GetSaveFolderItem function.