Mar*_*eIV 1 c# mailto url wpf process.start
不知道为什么会这样,但下面的行会使我们的 WPF 应用程序崩溃......
Process.Start("mailto:example@stackoverflow.com");
Run Code Online (Sandbox Code Playgroud)
这是例外情况:
System.ComponentModel.Win32Exception
HResult=0x80004005
Message=The system cannot find the file specified.
Source=System.Diagnostics.Process
StackTrace:
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
Run Code Online (Sandbox Code Playgroud)
注意:没有报告“InnerException”。
我通过编写这个带有超链接的简单 HTML 文件来测试,确认邮件处理程序已正确注册mailto:...
System.ComponentModel.Win32Exception
HResult=0x80004005
Message=The system cannot find the file specified.
Source=System.Diagnostics.Process
StackTrace:
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
Run Code Online (Sandbox Code Playgroud)
单击链接,邮件客户端将按预期打开!
根据网站上的另一篇文章,我还通过导入此方法尝试了混合交互方法...
<html>
<body>
<a href="mailto:example@stackoverflow.com">example@stackoverflow.com</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
然后像这样使用它...
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
Run Code Online (Sandbox Code Playgroud)
但我得到同样的例外。
那么什么可能导致这种情况呢?
小智 11
尝试设置 UseShellExecute:
System.Diagnostics.Process.Start(new ProcessStartInfo("mailto:example@stackoverflow.com") { UseShellExecute = true });
Run Code Online (Sandbox Code Playgroud)