c# - C#打开文本文件,如双击
问题描述
在.net框架中,当我需要像双击行为一样打开文本文件时,我使用了以下代码
System.Diagnostics.Process.Start(path);
当我尝试在核心中使用时出现此错误
System.ComponentModel.Win32Exception:“指定的可执行文件不是此 OS 平台的有效应用程序。”
此异常最初是在此调用堆栈中引发的: System.Diagnostics.Process.StartWithCreateProcess(System.Diagnostics.ProcessStartInfo) System.Diagnostics.Process.Start() System.Diagnostics.Process.Start(System.Diagnostics.ProcessStartInfo) System.Diagnostics .Process.Start(string) 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() ... [调用堆栈被截断]
我阅读了很多问题并尝试了解决方案,但不适合我。
解决方案
您可以通过执行以下操作使用其默认应用程序(在 Windows 中设置)打开文件:
Process fileopener = new Process();
fileopener.StartInfo.FileName = "explorer";
fileopener.StartInfo.Arguments = "\"" + pathToFile + "\"";
fileopener.Start();
推荐阅读
- c++ - c++ 带参数的结构指针
- wordpress - 如何使 div 或 id 仅对登录的 wordpress 作者可见
- python - 如何将 Scrapy 脚本转换为 .exe 文件?
- c - 有没有办法获取 main() 的变量参数并在我自己的函数中使用它们?
- html - Bootstrap 导航栏切换器在移动设备上不起作用
- docker - 在 docker 容器中为非 root 安装目录 r/w
- arrays - Kotlin 将字符串拆分为范围
- java - 如何在 Spring Boot 中正确映射 oneTomany 和 manyToone
- r - 我在 Docker 中使用 R 。但是在运行库时出错
- java - Android中的MainActivity文件