Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8944647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:04:35+00:00 2026-06-15T12:04:35+00:00

From c#, I want to launch a process which will open a text file

  • 0

From c#, I want to launch a process which will open a text file in any editor and automatically move cursor to a certain line number.

I can open a file using

Process.Start(@"c:\myfile.txt");

but I don’t know how to move cursor at specific location in that file.


Answer with source code:

yes, I used notepad++

private void openLog() {
            try {
                // see if notepad++ is installed on user's machine
                var nppDir = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Notepad++", null, null);
                if (nppDir != null) {
                    var nppExePath = Path.Combine(nppDir, "Notepad++.exe");
                    var nppReadmePath = Path.Combine(yourDirectory,fileName );
                    var line = 20;
                    var sb = new StringBuilder();
                    sb.AppendFormat("\"{0}\" -n{1}", nppReadmePath, lineNo);
                    Process.Start(nppExePath, sb.ToString());
                } else {
                    string newPath = @"\\mySharedDrive\notpad++\bin\notepad++.exe";
                    Process.Start(newPath, @"\\" + filePath + " -n" + lineNo); // take exe from my shared drive
                }
            } catch (Exception e) {
                Process.Start(@"\\" + FilePath); // open using notepad
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:04:36+00:00Added an answer on June 15, 2026 at 12:04 pm

    Get Notepad++, then you can do this:

        var nppDir = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Notepad++", null, null);
        var nppExePath = Path.Combine(nppDir, "Notepad++.exe");
        var nppReadmePath = Path.Combine(nppDir, "readme.txt");
        var line = 20;
        var sb = new StringBuilder();
        sb.AppendFormat("\"{0}\" -n{1}", nppReadmePath, line);
        Process.Start(nppExePath, sb.ToString());
    

    In this example we get install path of n++ from the registry, build path to exe and readme.txt file, opens its own readme.txt file with cursor on line 20.
    Using StringBuilder is more efficient than using multiple appends (explanation somewhere on SO).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to deploy a firebird installation, and thus will launch it from my
I want to be able to launch a Java server process from an existing
I want to launch a process in suspended state. Is there any way to
There were some windows opened, And from my process I want to launch one
I want to launch from my application the activity recent apps, without holding on
I want to launch games from my apps in Windows. Many of these games
I want to launch an app on OSX from a script. I need to
I have a Main form.I want to launch another form from it and launch
I have a Makefile from which I want to call another external bash script
I want to launch ~10 php processes from a bash script. When one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.