在C#中以已知文件名启动记事本 [英] Starting Notepad with a Known Filename within C#

查看:34
本文介绍了在C#中以已知文件名启动记事本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中包含以下代码-

I have the following code in my application --

if (File.Exists("c:\\a.txt"))
{
  try
  {
     Process z = Process.Start("notepad c:\\a.txt");                
  }

  catch(Exception ex)
  {
      MessageBox.Show(ex.Message.ToString());
  }
}




我收到一个消息框,指出系统找不到指定的文件"

谁能告诉我如何启动记事本(显示文件)吗?




I get a messagebox that states "The system cannot find the file specified"

Can Anyone tell me how to start notepad (to display the file)??

推荐答案

使用方法 Start(String programFile, String arguments) [
You have the finest control using the method Start(ProcessStartInfo psi)[^], but in your case the method Start(String programFile, String arguments)[^] will suffice. The parameter programFile will be the full path to notepad.exe and the file you want to load will given in the parameter arguments.

Regards,

Manfred


尝试:
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo("Notepad.Exe", @"D:\Temp\MyLargeTextFile.txt");
p.StartInfo = psi;
p.Start();


考虑使用shell execute命令.在这种情况下,将打开与txt文件相关的应用程序.在许多情况下,这将是标准的Windows记事本,但有些人,例如我;-)则喜欢使用不同的编辑器,例如Notepad ++等.
Consider using the shell execute command. In this case, the associated application for txt-files will open. In many cases this will be standard windows notepad, but some people, like me ;-), prefer different editors like Notepad++ etc.

Process foo = new Process();
foo.StartInfo.UseShellExecute = true;
foo.StartInfo.FileName = "filename.txt";
foo.Start();


这篇关于在C#中以已知文件名启动记事本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆