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

Open File Dialog Dialog Control

The Open 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 open file dialog appears, allowing them to navigate to and select an existing file. The selected file 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 an Open File Dialog onto a dialog page. Set the Filter property to restrict which file types appear in the dialog, and optionally set InitialDir to control which folder opens by default. The control default size is 200 ร— 22 pixels.


Properties

PropertyTypeDefaultDescription
FileNameStringThe full path of the selected file. Updated when the user picks a file or types directly into the text box. Read this from script to use the selected path.
FilterStringRestricts the file types shown in the dialog. Uses the standard Windows filter format: Description|*.ext;*.ext2|Description2|*.ext3
FilterIndexInteger1The 1-based index of the filter entry that is selected by default when the dialog opens
DefaultExtStringFile extension appended automatically if the user types a filename without one (e.g. xlsx)
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 selected file in BeforeStartReport

procedure BeforeStartReport;
begin
  if TrimSafe(OpenFileDialog1.FileName) = '' then
    RaiseException('Please select a file to import.');

  // Use the path โ€” for example load it into a TfrxFDMemTable
  FDMemTable1.LoadFromFile(OpenFileDialog1.FileName);
end;

Filtering by file type

// Show only Excel files and all files
OpenFileDialog1.Filter := 'Excel Files|*.xlsx;*.xls|All Files|*.*';
OpenFileDialog1.FilterIndex := 1;

Setting a default starting folder

// Open in the Articles report folder by default
OpenFileDialog1.InitialDir := GetReportFolder;

// Or open in a specific path
OpenFileDialog1.InitialDir := 'C:\Data\Imports';

Reading the selected path after the dialog

// Display the selected file name in a report variable
Report.Variables['ImportFile'] := OpenFileDialog1.FileName;

// Show just the filename without the full path
var fullPath := OpenFileDialog1.FileName;
var fname    := RightStr(fullPath,
                  Length(fullPath) - LastDelimiter('\', fullPath));
Report.Variables['ImportFileName'] := fname;

Common filter strings

// CSV files
OpenFileDialog1.Filter := 'CSV Files|*.csv|All Files|*.*';

// Images
OpenFileDialog1.Filter := 'Image Files|*.jpg;*.jpeg;*.png;*.bmp|All Files|*.*';

// Text and CSV
OpenFileDialog1.Filter := 'Text Files|*.txt;*.csv|All Files|*.*';

// XML and JSON
OpenFileDialog1.Filter := 'Data Files|*.xml;*.json|All Files|*.*';