Can you open a notepad txt file from c# code?

  • Thread starter Thread starter Ken Adams
  • Start date Start date
K

Ken Adams

Basically I want to know how you could open a txt file in notepad through c#
code. I don't want to read in the data or anything like that I just want to
open the file just as it would have been if you double clicked it. Doesn't
necessarily have to be notepad I might add. Any suggestions? Thanks a bunch.


Ken
 
Ken said:
Basically I want to know how you could open a txt file in notepad
through c# code. I don't want to read in the data or anything like
that I just want to open the file just as it would have been if you
double clicked it. Doesn't necessarily have to be notepad I might
add. Any suggestions? Thanks a bunch.

Ken

What you are talking about is writing your own WinForm Notepad application
from scratch. you'd want to have the Main() method command-line argument
read in the file and then you'd open it using a FileStream object, and then
render it in a window however you want.
 
If you really want to handle it this way you should look at starting a
process using something like:

System.Diagnostics.Process.Start("notepad.exe", @"C:\temp\TheFile.txt");

The first parameter is the name of the application you want to launch
while the second is the parameters you want to send to it. In this case
notepad accepts the name of a file to open. Anyway it should accomplish
what you asked for.

Have A Better One!

John M Deal, MCP
Necessity Software
 
If the .txt extension is associated with Notepad, you can simply call this:

System.Diagnostics.Process.Start("YourFile.txt");

Note that this will work with any extension. This is like ShellExecute in
Win32.
 
Back
Top