Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After converting WPF MS framework 4.8 project to net 8
the process.start(url) no longer works.

private void DG_Hyperlink_Click(object sender, RoutedEventArgs e)
{
Hyperlink link = (Hyperlink)e.OriginalSource;
Process.Start(link.NavigateUri.AbsoluteUri);


Quote:
System.ComponentModel.Win32Exception: "An error occurred trying to start process 'https://docs.microsoft.com/en-us/windows/communitytoolkit/mvvm/introduction' with working directory 'E:\Visual Studio\Code Project\DataGridPlus\DataGridPlus\bin\Debug\net8.0-windows'. Das System kann die angegebene Datei nicht finden."

=> cannot find related file

How do I fix this?

What I have tried:

Tried a variant for start url:

Hyperlink link = (Hyperlink)e.OriginalSource;
new ProcessStartInfo("start " + link.NavigateUri.AbsoluteUri);
Posted
Updated 21-Apr-24 5:57am
v2

Try setting UseShellExecute to true. This will use the default application to start the process. https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.useshellexecute?view=net-8.0#system-diagnostics-processstartinfo-useshellexecute
 
Share this answer
 
Comments
Jo_vb.net 21-Apr-24 13:22pm    
Tried

using (Process compiler = new Process())
{
compiler.StartInfo.FileName = "explorer.exe";

compiler.StartInfo.Arguments = link.NavigateUri.AbsoluteUri;
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
//Console.WriteLine(compiler.StandardOutput.ReadToEnd());

compiler.WaitForExit();

Shows error:// "No process is associated with this object."


Found this solution (not default browser but it works)

Process.Start("explorer.exe", link.NavigateUri.AbsoluteUri);

Thanks for your help.
Pete O'Hanlon 21-Apr-24 13:36pm    
You set it to false in your code. It needs to be true.
Jo_vb.net 21-Apr-24 14:00pm    
Unfortunately with
compiler.StartInfo.UseShellExecute = true;
the same error happens as before.
Here is a working example:
C#
string link = "https://docs.microsoft.com/en-us/windows/communitytoolkit/mvvm/introduction";

Process? process = Process.Start(new ProcessStartInfo(link)
{
    UseShellExecute = true
});

process!.WaitForExit();

You can also see it in use in this .Net Core article: .NET Silent ClickOnce Installer for Winform & WPF in C# & VB[^]
 
Share this answer
 
v2
Comments
Jo_vb.net 21-Apr-24 19:47pm    
Great + thanks.

Adjusted it and that works:

private void DG_Hyperlink_Click(object sender, RoutedEventArgs e)
{

Hyperlink link = (Hyperlink)e.OriginalSource;
Process? process = Process.Start(new ProcessStartInfo(link.NavigateUri.AbsoluteUri)
{
UseShellExecute = true
});

process!.WaitForExit();
}
Graeme_Grant 24-Apr-24 4:52am    
All good. I would have gone into more details however was on the way out the door to take the wife & kids camping...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900