C#用记事本打开文件

编程入门 行业动态 更新时间:2024-10-27 02:21:31
本文介绍了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#用记事本打开文件

本文发布于:2023-11-11 11:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578255.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:记事本   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!