PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.

Open text file in notepad from C#

 
 
Jesper
Guest
Posts: n/a
 
      23rd Oct 2003
How can I open a textfile from C# using notepad (or the
user assigned application for this).
 
Reply With Quote
 
 
 
 
Morten Wennevik
Guest
Posts: n/a
 
      23rd Oct 2003
On Thu, 23 Oct 2003 06:38:29 -0700, Jesper
<(E-Mail Removed)> 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/
 
Reply With Quote
 
 
 
 
Santiago
Guest
Posts: n/a
 
      23rd Oct 2003
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" <(E-Mail Removed)> wrote in message
newsprxh0s4d6hntkfz@localhost...
On Thu, 23 Oct 2003 06:38:29 -0700, Jesper
<(E-Mail Removed)> 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/


 
Reply With Quote
 
Morten Wennevik
Guest
Posts: n/a
 
      24th Oct 2003
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/
 
Reply With Quote
 
Santiago
Guest
Posts: n/a
 
      24th Oct 2003
You are correct. Must have only read half the post.
I eat my shoe

- Santiago

"Morten Wennevik" <(E-Mail Removed)> wrote in message
newsprxjbirb0hntkfz@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/


 
Reply With Quote
 
New Member
Join Date: Dec 2011
Posts: 3
 
      2nd Aug 2012
As an alternative may I suggest using a notepad clone instead that way you have full control. I wrote an exact clone of notepad exactly for this purpose. You can find the source code here: http://www.simplygoodcode.com/2012/0...-winforms.html
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is notepad, and how do I open a vcard to view it in notepad? =?Utf-8?B?TW9yVFRpbWU=?= Microsoft Outlook Contacts 2 12th Aug 2005 06:34 PM
Replace Notepad with Notepad+ Don Schmidt Windows XP General 3 3rd Aug 2005 02:48 PM
Notepad won't open any files (PROBLEM WITH XP & NOTEPAD) leni Windows XP General 1 11th Jul 2004 01:52 PM
BUG: Notepad being blocked when folder notepad is on Desktop of user Aprazeth Windows XP Internet Explorer 0 23rd Oct 2003 11:41 PM
notepad.exe launches Windows Debugger instead of notepad application Mohammad Hashim Windows XP General 2 11th Oct 2003 08:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:55 AM.