6

The answer to this question shows how to launch Edge with a web URL from C#:

System.Diagnostics.Process.Start("microsoft-edge:http://www.google.com");

However, this doesn't seem to work with file URLs.

System.Diagnostics.Process.Start("microsoft-edge:file:///C:/foo/bar.html");

launches Edge, but the file is not displayed. Instead, Edge opens to its default page. Pasting the same URL ("file:///C:/foo/bar.html") into the Edge address bar works fine, and if I right-click the file in Explorer and choose Open With->Edge, the same URL appears in the address bar.

Does anyone know how to launch Edge with a file URL?

TIA

Community
  • 1
  • 1
chrisd
  • 853
  • 1
  • 9
  • 23
  • possible duplicate of [https://stackoverflow.com/questions/34798285/how-can-i-open-a-local-html-file-in-microsoft-edge-browser](https://stackoverflow.com/questions/34798285/how-can-i-open-a-local-html-file-in-microsoft-edge-browser) – mahlatse Aug 26 '18 at 15:27
  • Currently you cannot open local files through `microsoft-edge` url scheme. There is a feature request in uservoice regarding to this feature: [Allow to open local files from Command Line](https://wpdev.uservoice.com/forums/257854-microsoft-edge-developer/suggestions/11422089-allow-to-open-local-files-from-command-line) – Reza Aghaei Aug 26 '18 at 17:38

3 Answers3

3

As noted in the comments, Edge does not support the file: protocol via the command line at this time.

However, it is currently possible to launch Edge with a local file using IApplicationActivationManager. The necessary code can be extracted from the C# version of MicrosoftEdgeLauncher and integrated into a C# application.

See 'MicrosoftEdgeLauncherCsharp' at https://github.com/MicrosoftEdge/edge-launcher. To launch with a local file, use 'file:///d:/path/filename.ext' as the arguments parameter to ActivateApplication.

chrisd
  • 853
  • 1
  • 9
  • 23
3

One dirty solution: first set your default launcher as Edge.

Suppose the file you want to open is file:///C:/foo/bar.html, you can launch it using explorer:

explorer file:///C:/foo/bar.html

Which will open Edge with the HTML for you. This seems to be the only solution after start microsoft-edge:file:///C:/foo/bar.html no longer works.

ice1000
  • 6,406
  • 4
  • 39
  • 85
0

With C# 10 on .Net6 and Win10, only the following worked for me:

 Process.Start("msedge", "d:/myfile.html");

There are a number of other answers on the site which don't appear to work any more.

Tullochgorum
  • 471
  • 5
  • 10