1. Home
  2. /
  3. Docs
  4. /
  5. Articles Report Writer
  6. /
  7. Dialog Components
  8. /
  9. Save File Dialog Dialog C...

Save File Dialog Dialog Control

The Save File Dialog control places a text box with a browse button on a report dialog page. When the user clicks the button, the standard Windows save file dialog appears, allowing them to choose a location and filename for a file to be saved. The selected path is stored in the FileName property and is available in script throughout the report.

The user can also type a path directly into the text box without using the browse button.


Adding to a Report

Drop a Save File Dialog onto a dialog page. Set the Filter property to restrict which file types are offered, set DefaultExt so the correct extension is appended automatically, and optionally set InitialDir to control which folder the dialog opens in. The control default size is 200 ร— 22 pixels.


Properties

PropertyTypeDefaultDescription
FileNameStringThe full path chosen by the user. Updated when the user picks a location or types directly into the text box. Read this from script to use as the save destination.
FilterStringRestricts the file types shown in the dialog. Uses the standard Windows filter format: Description|*.ext|Description2|*.ext2
FilterIndexInteger1The 1-based index of the filter entry selected by default when the dialog opens
DefaultExtStringFile extension appended automatically if the user types a filename without one (e.g. pdf). Include without the leading dot.
InitialDirStringThe folder the dialog opens in by default. Leave blank to use the system default.
TitleStringCustom title bar text for the dialog window. Leave blank for the system default title.

Examples

Reading the chosen save path in BeforeStartReport

procedure BeforeStartReport;
begin
  if TrimSafe(SaveFileDialog1.FileName) = '' then
    RaiseException('Please choose a save location before running the report.');

  Report.Variables['ExportPath'] := SaveFileDialog1.FileName;
end;

Saving a report export to the chosen path

procedure BeforeStartReport;
var
  savePath: String;
begin
  savePath := TrimSafe(SaveFileDialog1.FileName);
  if savePath = '' then
    RaiseException('Please choose a file to save to.');

  // The export path can be used after the report runs
  // to save to the user-specified location
  Report.Variables['SavePath'] := savePath;
end;

Setting a default filename and extension

// Default to saving as a PDF in the report folder
SaveFileDialog1.DefaultExt  := 'pdf';
SaveFileDialog1.InitialDir  := GetReportFolder;
SaveFileDialog1.Filter      := 'PDF Files|*.pdf|All Files|*.*';
SaveFileDialog1.FileName    := 'SalesReport.pdf';

Building a dated default filename

// Suggest a filename that includes today's date
SaveFileDialog1.FileName := 'SalesReport_' +
  FormatDateTime('yyyymmdd', Date) + '.xlsx';
SaveFileDialog1.DefaultExt := 'xlsx';
SaveFileDialog1.Filter := 'Excel Files|*.xlsx|All Files|*.*';

Common filter strings

// PDF only
SaveFileDialog1.Filter     := 'PDF Files|*.pdf|All Files|*.*';
SaveFileDialog1.DefaultExt := 'pdf';

// Excel
SaveFileDialog1.Filter     := 'Excel Files|*.xlsx|All Files|*.*';
SaveFileDialog1.DefaultExt := 'xlsx';

// CSV
SaveFileDialog1.Filter     := 'CSV Files|*.csv|All Files|*.*';
SaveFileDialog1.DefaultExt := 'csv';