forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Dialog
github-actions[bot] edited this page Oct 15, 2025
·
2 revisions
Display native system dialogs for opening and saving files, alerting, etc.
The Electron.Dialog API provides access to native system dialogs for file operations, message boxes, and certificate trust dialogs. These dialogs are modal and provide a consistent user experience across different platforms.
Parameters:
-
browserWindow(optional) - Parent window for modal behavior -
options- Dialog configuration options
Returns: Array of selected file paths
Parameters:
-
browserWindow(optional) - Parent window for modal behavior -
options- Dialog configuration options
Returns: Selected file path or empty string if cancelled
Parameters:
-
browserWindow(optional) - Parent window for modal behavior -
messageormessageBoxOptions- Message content and configuration
Returns: MessageBoxResult with response index and checkbox state
Parameters:
-
title- Dialog title -
content- Error message content
Parameters:
-
browserWindow(optional) - Parent window for modal behavior -
options- Certificate trust dialog options
var options = new OpenDialogOptions
{
Title = "Select Files",
DefaultPath = "/home/user/documents",
ButtonLabel = "Select",
Properties = new[]
{
OpenDialogProperty.OpenFile,
OpenDialogProperty.MultiSelections,
OpenDialogProperty.CreateDirectory
},
Filters = new[]
{
new FileFilter { Name = "Images", Extensions = new[] { "jpg", "png", "gif" } },
new FileFilter { Name = "All Files", Extensions = new[] { "*" } }
}
};var options = new SaveDialogOptions
{
Title = "Save As",
DefaultPath = "document.txt",
ButtonLabel = "Save",
Filters = new[]
{
new FileFilter { Name = "Text Files", Extensions = new[] { "txt" } }
}
};var options = new MessageBoxOptions
{
Type = MessageBoxType.Info,
Title = "Information",
Message = "Operation completed successfully.",
Buttons = new[] { "OK" },
DefaultId = 0,
CancelId = 0
};- File vs Directory Selection: Cannot show both file and directory selection simultaneously
- Property Priority: If both
openFileandopenDirectoryare set, directory selection takes precedence
- Certificate Dialogs: Full certificate trust dialog support
- File Type Handling: Enhanced file type filtering and preview
// Open multiple files
var files = await Electron.Dialog.ShowOpenDialogAsync(window, new OpenDialogOptions
{
Properties = new[] { OpenDialogProperty.OpenFile, OpenDialogProperty.MultiSelections }
});
// Save with custom extension
var path = await Electron.Dialog.ShowSaveDialogAsync(window, new SaveDialogOptions
{
DefaultPath = "backup.json",
Filters = new[] { new FileFilter { Name = "JSON", Extensions = new[] { "json" } } }
});// Confirmation dialog
var result = await Electron.Dialog.ShowMessageBoxAsync(window, new MessageBoxOptions
{
Type = MessageBoxType.Question,
Title = "Confirm Delete",
Message = $"Delete {filename}?",
Buttons = new[] { "Cancel", "Delete" },
DefaultId = 0,
CancelId = 0
});
if (result.Response == 1)
{
// Delete file
}// Error dialog
Electron.Dialog.ShowErrorBox("Save Failed", "Could not save file. Please check permissions and try again.");
// Warning dialog
await Electron.Dialog.ShowMessageBoxAsync(new MessageBoxOptions
{
Type = MessageBoxType.Warning,
Title = "Warning",
Message = "This operation may take several minutes.",
Buttons = new[] { "Continue", "Cancel" }
});- Electron.WindowManager - Parent windows for modal dialogs
- Electron.App - Application lifecycle events
- Electron.Shell - File operations with selected paths
- Electron Dialog Documentation - Official Electron dialog API
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.