通过按钮单击事件打开链接/文件

问题描述 投票:-1回答:1

我还是WPF / XAML编码的新手,在学习的过程中遇到了另一个问题。我决定在UserControl上添加按钮,我想让他们做一些不同的事情。在其中一个上,我想打开本地默认浏览器并打开一个网页链接,在另一个按钮中,我想从我项目中名为“tools”的目录中启动一个本地exe / rpm文件。

为了打开我试过的链接 - WebBrowserTask这是一个无法识别的事件/任务

对于应用程序的运行 - Process.Start("thelocation/thefile.exe/rdp")。之后,我尝试将其引导到正确的路径,但我的项目无法识别其中的文件夹和文件。

两次尝试都没有成功。

c# wpf xaml wpf-controls
1个回答
0
投票

试试这个:

public void DoSomething 
{
    const string webpageUrl = "https://stackoverflow.com/questions/55778625/";
    const string localFile = @"C:\Windows\notepad.exe";
    var localTools = $@"{AppDomain.CurrentDomain.BaseDirectory}Tools\SomeTools.exe";

    Process.Start(webpageUrl);
    Process.Start(localFile);
    Process.Start(localTools);
}

要打开网页,您的地址必须以http://开头...

© www.soinside.com 2019 - 2024. All rights reserved.