# ShowSave
{: .no_toc }

Shows the Save As dialog and returns the file name that the user chose.

Syntax: *object*.**ShowSave** ( ) **As String**

*object*
: *required* An object expression that evaluates to a **cDialog**.

Returns a **String**, the full path that the user confirmed, or an empty string when the user cancelled.

## Remarks

**ShowSave** calls `GetSaveFileNameW` and takes its options from the properties of the object:

| Property | What **ShowSave** passes |
|---|---|
| [**DialogTitle**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/DialogTitle.md) | `lpstrTitle`, the title |
| [**InitialDir**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/InitialDir.md) | `lpstrInitialDir`, the starting folder |
| [**FileName**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/FileName.md) | `lpstrFile`, the text in the File name box when the dialog opens |
| [**Filter**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/Filter.md) | `lpstrFilter`, the file-type list |
| [**DefaultExt**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/DefaultExt.md) | `lpstrDefExt`, the extension added to a name typed without one |
| [**OverwritePrompt**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/OverwritePrompt.md) | `OFN_OVERWRITEPROMPT` |
| [**PathMustExist**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/PathMustExist.md) | `OFN_PATHMUSTEXIST` |
| [**HideReadOnly**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/HideReadOnly.md) | `OFN_HIDEREADONLY` |
| [**NoChangeDir**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/NoChangeDir.md) | `OFN_NOCHANGEDIR` |

A flag is set when its property is **True**. Unlike [**ShowOpen**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/ShowOpen.md), **ShowSave** never sets `OFN_ALLOWMULTISELECT`, `OFN_FILEMUSTEXIST`, `OFN_READONLY` or `OFN_CREATEPROMPT`, so [**MultiSelect**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/MultiSelect.md), [**FileMustExist**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/FileMustExist.md), [**ReadOnly**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/ReadOnly.md) and [**CreatePrompt**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/CreatePrompt.md) have no effect on it. The method always sets `OFN_LONGNAMES`, `OFN_EXPLORER` and `OFN_ENABLESIZING`, selects the first pair of the filter, and has no owner window, hook or template. The [class page](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/index.md#settings-without-a-property) lists these settings.

When the user confirms the dialog, **ShowSave** stores the path in [**FileName**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/FileName.md) as well as returning it. A cancelled dialog returns an empty string and leaves **FileName** as it was. The dialog returns only a name: it saves nothing, and the class does not create or write the file.

An empty string also results when Windows reports a failure, such as a path that does not fit into the buffer of 260 characters, and no value tells which of the two happened. Neither case raises an error.

With [**OverwritePrompt**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/OverwritePrompt.md) **True** and a file that exists, the box *Confirm Save As* asks whether to replace it. *Yes* returns the path, and *No* leaves the dialog open. With **False** there is no box and the path is returned. With [**DefaultExt**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/DefaultExt.md) set, a name typed without an extension gets it.

> [!NOTE] 1.1.0.0
> The class pads the buffer with spaces to 260 characters, and the dialog does not show the padding. A [**FileName**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/FileName.md) of 260 characters shows no dialog and returns an empty string at once, as a cancel does. A **FileName** of 261 characters or more makes **ShowSave** raise run-time error 5, *Invalid procedure call or argument*, before any dialog opens.

## Example

This example asks for a file name and writes a line to the file.

```tb check_build
Dim dlg As New cDialog
Dim path As String

dlg.DialogTitle = "Save the report"
dlg.DefaultExt = "txt"
dlg.FileName = "report.txt"
dlg.SetCommonFilters

path = dlg.ShowSave()
If Len(path) > 0 Then
    Open path For Output As #1
    Print #1, "Report"
    Close #1
End If
```

## See Also

- [ShowOpen](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/ShowOpen.md) method -- shows the Open dialog
- [ShowBrowseForFolder](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/ShowBrowseForFolder.md) method -- shows the Browse For Folder dialog
- [DefaultExt](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/DefaultExt.md) property -- the extension added to a name typed without one
- [OverwritePrompt](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/OverwritePrompt.md) property -- asks before a name that exists is accepted
- [FileName](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/FileName.md) property -- the suggested name and the result
- [cDialog](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/index.md) class -- overview
