【问题标题】:C# Open text file like Double Click [duplicate]C#打开文本文件,如双击[重复]
【发布时间】:2020-12-21 10:09:31
【问题描述】:

在 .net 框架中 当我需要像双击行为一样打开文本文件时,我使用了以下代码

System.Diagnostics.Process.Start(path);

当我尝试在核心中使用时出现此错误

System.ComponentModel.Win32Exception: '指定的可执行文件不是此操作系统平台的有效应用程序。'

此异常最初是在此调用堆栈中引发的: System.Diagnostics.Process.StartWithCreateProcess(System.Diagnostics.ProcessStartInfo) System.Diagnostics.Process.Start() System.Diagnostics.Process.Start(System.Diagnostics.ProcessStartInfo) System.Diagnostics.Process.Start(字符串) HandelString.cs 中的 AccountManager.Setting.HandelString.Encrypt(string) Main.cs 中的 AccountManager.Main.Main_Load(object, System.EventArgs) System.Windows.Forms.Form.OnLoad(System.EventArgs) System.Windows.Forms.Form.OnCreateControl() System.Windows.Forms.Control.CreateControl(bool) System.Windows.Forms.Control.CreateControl() ... [调用堆栈被截断]

Error Message Here

我阅读了很多问题并尝试了解决方案,但不适合我。

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    您可以通过执行以下操作使用其默认应用程序(在 Windows 中设置)打开文件:

    Process fileopener = new Process();
    fileopener.StartInfo.FileName = "explorer";
    fileopener.StartInfo.Arguments = "\"" + pathToFile + "\"";
    fileopener.Start();
    

    【讨论】:

      猜你喜欢
      • 2011-01-01
      • 1970-01-01
      • 2016-10-27
      • 2012-03-04
      • 2020-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-19
      相关资源
      最近更新 更多