Skip to content

OpenFileDialog.ShowDialog

method · OpenFileDialog · cAlgo.API Since 5.1

DesktopCLICloud

Shows a file dialog, with the owner as the main Window

Environment behaviour

CLI — not supported. No dialog is shown. Returns FileDialogResult.None; FileName and FileNames are unchanged.

Cloud — not supported. No dialog is shown. Returns FileDialogResult.None; FileName and FileNames are unchanged.

Overloads

Signature Description
ShowDialog() Shows a file dialog, with the owner as the main Window
ShowDialog(Window owner) Shows a file dialog, with the passed owner window.

ShowDialog()

Shows a file dialog, with the owner as the main Window

public FileDialogResult ShowDialog()
openFileDialog.ShowDialog() -> FileDialogResult

Returns FileDialogResult

Examples

var openFileDialog = new OpenFileDialog { Filter = "CSV files (*.csv)|*.csv" };
var result = openFileDialog.ShowDialog();
if (result == FileDialogResult.OK)
    Print("Importing {0}", openFileDialog.FileName);
else
    Print("Dialog result: {0}", result);
openFileDialog = OpenFileDialog()
openFileDialog.Filter = "CSV files (*.csv)|*.csv"
result = openFileDialog.ShowDialog()
if result == FileDialogResult.OK:
    api.Print(f"Importing {openFileDialog.FileName}")
else:
    api.Print(f"Dialog result: {result}")

ShowDialog(Window owner)

Shows a file dialog, with the passed owner window.

public FileDialogResult ShowDialog(Window owner)
openFileDialog.ShowDialog(owner: Window) -> FileDialogResult

Parameters

Name C# type Python type Description
owner Window Window The window that owns the file dialog.

Returns FileDialogResult

Examples

var window = new Window { Title = "Import", Width = 300, Height = 150 };
var browseButton = new Button { Text = "Browse" };
browseButton.Click += args =>
{
    var openFileDialog = new OpenFileDialog();
    if (openFileDialog.ShowDialog(window) == FileDialogResult.OK)
        Print("File: {0}", openFileDialog.FileName);
};
window.Child = browseButton;
window.Show();
window = Window()
window.Title = "Import"
window.Width = 300
window.Height = 150
window.Show()
openFileDialog = OpenFileDialog()
if openFileDialog.ShowDialog(window) == FileDialogResult.OK:
    api.Print(f"File: {openFileDialog.FileName}")