-3

The code:

private void viewLogFileToolStripMenuItem_Click(object sender, EventArgs e)
{
     string path_log = Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\log";
     string logger_file = @"\logger.txt";
     string LoggerFileName = Path.Combine(path_log, logger_file);    
}

I want when I click the menu item it will open the LoggerFileName automatic in notepad and show me the notepad window .

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
joneK
  • 241
  • 1
  • 4
  • 13

4 Answers4

2

if txt file default open application set as notepad you can open it as below

System.Diagnostics.Process.Start(LoggerFileName);

below will open notepad with given file

System.Diagnostics.Process.Start("notepad.exe", LoggerFileName);

Note :

string LoggerFileName = Path.Combine(
                      Path.GetDirectoryName(Application.LocalUserAppDataPath), 
                     "log", 
                     "logger.txt");
Damith
  • 62,401
  • 13
  • 102
  • 153
  • So basically rip the answers out of http://stackoverflow.com/questions/4055266/open-a-file-with-notepad-in-c-sharp ? – It'sNotALie. Jun 08 '13 at 16:17
  • the first usually opens file with notepad but in some case if txt file is opened by another application as default, that application will show the file content. – King King Jun 08 '13 at 16:18
  • `"notepad"` can also work as well as `"notepad.exe"` :), just some helpful comment for others. :) – King King Jun 08 '13 at 16:23
1

Have you even researched this at all?

private void viewLogFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string path_log = Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\log\";
            string logger_file = @"\logger.txt";
            string LoggerFileName = Path.Combine(path_log, logger_file);
            Process.Start(Path.Combine(Environment.SystemDirectory, @"\notepad.exe"), LoggerFileName);
        }

All you needed to google was really "get notepad path c#" and "start process c#".

It'sNotALie.
  • 22,289
  • 12
  • 68
  • 103
1

There is the Process class in the .Net framework.

Use it with ProcessStartInfo.UseShellExecute set to true. Then you can "start" the .txt file, and the user could've chosen it's favorite editor. The default, however, would be NotePad anyway.

JeffRSon
  • 10,404
  • 4
  • 26
  • 51
1

What about

   private void viewLogFileToolStripMenuItem_Click(object sender, EventArgs e)
   {
        string path_log = Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\log";
        string logger_file = @"\logger.txt";
        string LoggerFileName = Path.Combine(path_log, logger_file);
        string notepadPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System),"notepad.exe")
        Process.Start(notepadPath,LoggerFileName);
    }

?

kobigurk
  • 731
  • 5
  • 14