chrisd
chrisd

Reputation: 903

Launching Edge with a file URL

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

Upvotes: 7

Views: 7955

Answers (3)

Tullochgorum
Tullochgorum

Reputation: 531

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.

Upvotes: 1

ice1000
ice1000

Reputation: 6589

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.

Upvotes: 3

chrisd
chrisd

Reputation: 903

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.

Upvotes: 3

Related Questions