Skip to content
github-actions[bot] edited this page Oct 31, 2025 · 1 revision

Desktop integration for opening files, URLs, and accessing system paths.

Overview

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.

Methods

🧊 void Beep()

Play the beep sound.

🧊 Task<string> OpenExternalAsync(string url)

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.

🧊 Task<string> OpenExternalAsync(string url, OpenExternalOptions options)

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.

🧊 Task<string> OpenPathAsync(string path)

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.

🧊 Task<ShortcutDetails> ReadShortcutLinkAsync(string shortcutPath)

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.

🧊 Task ShowItemInFolderAsync(string fullPath)

Show the given file in a file manager. If possible, select the file.

Parameters:

  • fullPath - The full path to the directory or file

🧊 Task<bool> TrashItemAsync(string fullPath)

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.

Usage Examples

File Operations

// Open file with default applicationvarerror=awaitElectron.Shell.OpenPathAsync(filePath);if(string.IsNullOrEmpty(error)){Console.WriteLine("File opened successfully");}else{Console.WriteLine($"Failed to open file: {error}");}// Show file in file managerawaitElectron.Shell.ShowItemInFolderAsync(filePath);// Move file to trashvartrashed=awaitElectron.Shell.TrashItemAsync(filePath);Console.WriteLine($"File trashed: {trashed}");

URL Operations

// Open URL in default browservarerror=awaitElectron.Shell.OpenExternalAsync("https://electron.net");if(!string.IsNullOrEmpty(error)){Console.WriteLine($"Failed to open URL: {error}");}// Open email clientawaitElectron.Shell.OpenExternalAsync("mailto:[email protected]");// Open with optionsvarerror=awaitElectron.Shell.OpenExternalAsync("https://example.com",newOpenExternalOptions{Activate=true});

System Integration

// Play system beepElectron.Shell.Beep();// Create desktop shortcutvarsuccess=awaitElectron.Shell.WriteShortcutLinkAsync(@"C:\Users\Public\Desktop\MyApp.lnk",ShortcutLinkOperation.Create,newShortcutDetails{Target="C:\\Program Files\\MyApp\\MyApp.exe",Description="My Application",WorkingDirectory="C:\\Program Files\\MyApp"});// Read shortcut informationvardetails=awaitElectron.Shell.ReadShortcutLinkAsync(@"C:\Users\Public\Desktop\MyApp.lnk");Console.WriteLine($"Target: {details.Target}");

Integration with Dialog API

// Use with file dialog resultsvarfiles=awaitElectron.Dialog.ShowOpenDialogAsync(window,options);if(files.Length>0){varselectedFile=files[0];// Open the selected fileawaitElectron.Shell.OpenPathAsync(selectedFile);// Show in file managerawaitElectron.Shell.ShowItemInFolderAsync(selectedFile);}

Related APIs

Additional Resources

Clone this wiki locally