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
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
.
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.