2

I am creating a Windows Form Application and I want the user to be able to open the log file on request, after selecting the option on a menu strip.

I can open the file within notepad but the most recent entries will be at the end of the file. How would I make the application start at the end of the file to save the user a job?

My Current Code:

    public static void OpenCurrentLog()
    {
        Process process = new Process();
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = Environment.GetEnvironmentVariable("windir").ToString() + "\\system32\\notepad.exe";
        startInfo.Arguments = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +"\\" appName + "\\" + "\\LogFiles\\LogFile.log";
        startInfo.WindowStyle = ProcessWindowStyle.Normal;
        process.StartInfo = startInfo;
        process.Start();
        process.WaitForExit();
    }

Any Help would be appreciated. I am relatively new to c#.

default locale
  • 13,035
  • 13
  • 56
  • 62
  • 2
    Hi please see [Scrolling notepad using c#](http://stackoverflow.com/questions/9300635/scrolling-notepad-using-c-sharp-and-win32) – Karl-Henrik Apr 23 '14 at 11:39
  • 3
    I would hate your program. It forces Notepad onto the user. I never use Notepad and have a different text editor as my default. Why are you forcing Notepad onto the user? Since displaying a text file is a trivially easy thing to do in WinForms, why are you even opening up a separate process to view it. Just show a new form with a memo. – David Heffernan Apr 23 '14 at 11:47

1 Answers1

2

If you send CTRL (^) - END ({END}) through it will move to the bottom of the notepad file

SendKeys.Send("^{END}");

haxtbh
  • 3,467
  • 1
  • 21
  • 22