By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,435 Members | 1,967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,435 IT Pros & Developers. It's quick & easy.

Open text file in notepad from C#

P: n/a
How can I open a textfile from C# using notepad (or the
user assigned application for this).
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Thu, 23 Oct 2003 06:38:29 -0700, Jesper
<an*******@discussions.microsoft.com> wrote:
How can I open a textfile from C# using notepad (or the
user assigned application for this).


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

You might want to add a path to text.txt. (Remember to use @"C:\Path" or
"C:\\Path")

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2

P: n/a
That will not necessarily open notepad. It will open the text file with
whatever program is associated with .txt, that's by default notepad but can
be changed (on my system it's textpad). That is probably what you want but
in the case you want notepad explicitly, use:
System.Diagnostics.Process.Start( "notepad.exe", "text.txt");

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:oprxh0s4d6hntkfz@localhost...
On Thu, 23 Oct 2003 06:38:29 -0700, Jesper
<an*******@discussions.microsoft.com> wrote:
How can I open a textfile from C# using notepad (or the
user assigned application for this).


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

You might want to add a path to text.txt. (Remember to use @"C:\Path" or
"C:\\Path")

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #3

P: n/a
On Thu, 23 Oct 2003 12:33:31 -0700, Santiago <replytonewsgroup> wrote:
That will not necessarily open notepad. It will open the text file with
whatever program is associated with .txt, that's by default notepad but
can
be changed (on my system it's textpad). That is probably what you want
but
in the case you want notepad explicitly, use:
System.Diagnostics.Process.Start( "notepad.exe", "text.txt");

True, but he said to open the text file in notepad or whatever application
the user had assigned to text files.

Start( "notepad.exe", "text.txt" ) will most likely open notepad, but not
necessarily.
Windows doesn't keep track of where executables are kept when using
Process.Start so if notepad.exe isn't found in the directories listed in
Path it will throw an exception and fail.
You can overcome this by checking the registry to find out where a
registered application is.
HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/App Paths
Then again, notepad isn't registered as an application so that wouldn't
work.

In the end, it's best to let the user decide and just hand it over to
windows.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4

P: n/a
You are correct. Must have only read half the post.
I eat my shoe ;)

- Santiago

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:oprxjbirb0hntkfz@localhost...
On Thu, 23 Oct 2003 12:33:31 -0700, Santiago <replytonewsgroup> wrote:
That will not necessarily open notepad. It will open the text file with
whatever program is associated with .txt, that's by default notepad but
can
be changed (on my system it's textpad). That is probably what you want
but
in the case you want notepad explicitly, use:
System.Diagnostics.Process.Start( "notepad.exe", "text.txt");

True, but he said to open the text file in notepad or whatever application
the user had assigned to text files.

Start( "notepad.exe", "text.txt" ) will most likely open notepad, but not
necessarily.
Windows doesn't keep track of where executables are kept when using
Process.Start so if notepad.exe isn't found in the directories listed in
Path it will throw an exception and fail.
You can overcome this by checking the registry to find out where a
registered application is.
HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/App Paths
Then again, notepad isn't registered as an application so that wouldn't
work.

In the end, it's best to let the user decide and just hand it over to
windows.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.