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

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
 
M

Manco

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.
 
J

John M Deal

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
 
A

Ajay Kalra

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top