2

我想使用以下代码打开任何文件类型:

System.Diagnostics.Process.Start(pathFile);

有没有办法检查系统应用程序是否存在?

例如:pdf,本机没有acrobat reader。

我创建了一个try catch,但我对它不满意,我想模仿windows打开文件的行为。它有一个搜索网络/手动搜索的选项。

try
            {
                System.Diagnostics.Process.Start(pathFile);
            }
            catch (System.ComponentModel.Win32Exception ex)
            {

                composite.ReadingError = ex.Message;
                Console.WriteLine("error");
            }
4

2 回答 2

2

您需要使用 PInvoke ( FindExecutable (shell32)):

于 2010-04-27T01:12:01.020 回答
0

如果没有关联,它应该抛出一个Win32Exception你可以捕捉到的。

请参阅此处:http: //msdn.microsoft.com/en-us/library/53ezey2s.aspx在例外部分。

于 2010-04-27T00:58:32.850 回答