关于Process.Start的System.ComponentModel.Win32Exception异常的解决方案

问题

之前在.netframework中使用Process.Start(docname)可以直接打开这个文件,无需特别指定对应的程序,而在.netcore程序中,如果还是用同样方式的话,会出现下面错误。

原因

经过一些折腾,弄明白原因,是因为在.netframework和.netcore中对ProcessStartInfo参数UseShellExecute的默认值不同造成的。

解决方法

指定UseShellExecute = true
var p=new Process();
p.StartInfo = new ProcessStartInfo("readme.txt")
{
UseShellExecute = true
};
p.Start();
或者
指定appname
Process.Start("notepad.exe","readme.txt");

原文地址:https://www.cnblogs.com/newlifechou/p/15773865.html