Open text file in notepad from C#

Discussion in 'Microsoft C# .NET' started by Jesper, Oct 23, 2003.

  1. Jesper

    Jesper Guest

    How can I open a textfile from C# using notepad (or the
    user assigned application for this).
     
    Jesper, Oct 23, 2003
    #1
    1. Advertisements

  2. On Thu, 23 Oct 2003 06:38:29 -0700, Jesper
    <> 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/
     
    Morten Wennevik, Oct 23, 2003
    #2
    1. Advertisements

  3. Jesper

    Santiago Guest

    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" <> wrote in message
    news:blush:prxh0s4d6hntkfz@localhost...
    On Thu, 23 Oct 2003 06:38:29 -0700, Jesper
    <> 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/
     
    Santiago, Oct 23, 2003
    #3
  4. 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/
     
    Morten Wennevik, Oct 24, 2003
    #4
  5. Jesper

    Santiago Guest

    You are correct. Must have only read half the post.
    I eat my shoe ;)

    - Santiago

    "Morten Wennevik" <> wrote in message
    news:blush:prxjbirb0hntkfz@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/
     
    Santiago, Oct 24, 2003
    #5
  6. Jesper

    luisperezphd

    Joined:
    Dec 18, 2011
    Messages:
    3
    Likes Received:
    0
    luisperezphd, Aug 2, 2012
    #6
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cfyam

    run notepad in my ap

    cfyam, Jan 9, 2004, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    184
    Morten Wennevik
    Jan 9, 2004
  2. Ken Adams

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

    Ken Adams, Dec 3, 2004, in forum: Microsoft C# .NET
    Replies:
    3
    Views:
    1,485
    Ajay Kalra
    Dec 4, 2004
  3. Guest
    Replies:
    5
    Views:
    374
    Chris Dunaway
    Oct 3, 2006
  4. Daniel

    Open notepad

    Daniel, Jan 16, 2007, in forum: Microsoft C# .NET
    Replies:
    6
    Views:
    177
    Shailen Sukul
    Jan 16, 2007
  5. Learning.Net
    Replies:
    3
    Views:
    707
    Jon Skeet [C# MVP]
    Aug 8, 2007
Loading...

Share This Page