-
Notifications
You must be signed in to change notification settings - Fork 0
Shell
Desktop integration for opening files, URLs, and accessing system paths.
The Electron.Shell API provides system integration functionality for opening files and URLs with their default applications, managing trash/recycle bin, and creating/reading shortcut links.
Play the beep sound.
Open the given external protocol URL in the desktop's default manner (e.g., mailto: URLs in the user's default mail agent).
Parameters:
-
url- Max 2081 characters on windows
Returns:
The error message corresponding to the failure if a failure occurred, otherwise empty string.
Open the given external protocol URL with additional options.
Parameters:
-
url- Max 2081 characters on windows -
options- Controls the behavior of OpenExternal
Returns:
The error message corresponding to the failure if a failure occurred, otherwise empty string.
Open the given file in the desktop's default manner.
Parameters:
-
path- The path to the directory or file
Returns:
The error message corresponding to the failure if a failure occurred, otherwise empty string.
Resolves the shortcut link at shortcutPath. An exception will be thrown when any error happens.
Parameters:
-
shortcutPath- The path to the shortcut
Returns:
ShortcutDetails of the shortcut.
Show the given file in a file manager. If possible, select the file.
Parameters:
-
fullPath- The full path to the directory or file
Move the given file to trash and returns a bool status for the operation.
Parameters:
-
fullPath- The full path to the directory or file
Returns:
Whether the item was successfully moved to the trash.
🧊 Task<bool> WriteShortcutLinkAsync(string shortcutPath, ShortcutLinkOperation operation, ShortcutDetails options)
Creates or updates a shortcut link at shortcutPath.
Parameters:
-
shortcutPath- The path to the shortcut -
operation- Default is ShortcutLinkOperation.Create -
options- Structure of a shortcut
Returns:
Whether the shortcut was created successfully.
// Open file with default application
var error = await Electron.Shell.OpenPathAsync(filePath);
if (string.IsNullOrEmpty(error))
{
Console.WriteLine("File opened successfully");
}
else
{
Console.WriteLine($"Failed to open file: {error}");
}
// Show file in file manager
await Electron.Shell.ShowItemInFolderAsync(filePath);
// Move file to trash
var trashed = await Electron.Shell.TrashItemAsync(filePath);
Console.WriteLine($"File trashed: {trashed}");// Open URL in default browser
var error = await Electron.Shell.OpenExternalAsync("https://electron.net");
if (!string.IsNullOrEmpty(error))
{
Console.WriteLine($"Failed to open URL: {error}");
}
// Open email client
await Electron.Shell.OpenExternalAsync("mailto:[email protected]");
// Open with options
var error = await Electron.Shell.OpenExternalAsync("https://example.com", new OpenExternalOptions
{
Activate = true
});// Play system beep
Electron.Shell.Beep();
// Create desktop shortcut
var success = await Electron.Shell.WriteShortcutLinkAsync(
@"C:\Users\Public\Desktop\MyApp.lnk",
ShortcutLinkOperation.Create,
new ShortcutDetails
{
Target = "C:\\Program Files\\MyApp\\MyApp.exe",
Description = "My Application",
WorkingDirectory = "C:\\Program Files\\MyApp"
}
);
// Read shortcut information
var details = await Electron.Shell.ReadShortcutLinkAsync(@"C:\Users\Public\Desktop\MyApp.lnk");
Console.WriteLine($"Target: {details.Target}");// Use with file dialog results
var files = await Electron.Dialog.ShowOpenDialogAsync(window, options);
if (files.Length > 0)
{
var selectedFile = files[0];
// Open the selected file
await Electron.Shell.OpenPathAsync(selectedFile);
// Show in file manager
await Electron.Shell.ShowItemInFolderAsync(selectedFile);
}- Electron.Dialog - Select files to open with Shell
- Electron.App - Application lifecycle events
- Electron.Clipboard - Copy file paths for Shell operations
- Electron Shell Documentation - Official Electron shell API
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.