C#用记事本打开文件 [英] Open a file with Notepad in C#

查看:76
本文介绍了C#用记事本打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 C# 中打开文件?我的意思不是通过 textreader 和 readline() 来阅读它.我的意思是在记事本中将其作为独立文件打开.

How I open a file in c#? I don't mean reading it by textreader and readline(). I mean open it as an independent file in notepad.

推荐答案

你需要System.Diagnostics.Process.Start().

最简单的例子:

Process.Start("notepad.exe", fileName);

更通用的方法:

Process.Start(fileName);

第二种方法可能是更好的做法,因为这将导致 Windows Shell 使用关联的编辑器打开您的文件.此外,如果指定的文件没有关联,它将使用 Windows 中的 Open With... 对话框.

The second approach is probably a better practice as this will cause the windows Shell to open up your file with it's associated editor. Additionally, if the file specified does not have an association, it'll use the Open With... dialog from windows.

请注意评论中的人,感谢您的投入.我的快速和肮脏的答案略有偏差,我已经更新了答案以反映正确的方式.

这篇关于C#用记事本打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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