How Do You Programmatically Go To The End Of The A NotePad File If Opened By A Windows Form Application

StackOverflow https://stackoverflow.com/questions/23243002

  •  08-07-2023
  •  | 
  •  

Question

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#.

Was it helpful?

Solution

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top