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 8824869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:44:24+00:00 2026-06-14T06:44:24+00:00

In my project, I am trying to open a text file. Well the below

  • 0

In my project, I am trying to open a text file. Well the below code works but when the user click the button again and again, many files are being opened. (which I dont want)

System.Diagnostics.Process.Start(filePath);

I also tried this, File.Open and File.OpenText which are not opening the text file and also not showing any error (tried with try catch block)

File.Open(filePath); (or)
File.OpenText(filePath); (or)
FileStream fileStream = new FileStream(filePath, FileMode.Open);

I also tried this: (ERROR : Cannot be accessed with instance reference qualify with a type name instead)

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.Start(filePath);  /*red scribbles here*/
proc.WaitForExit();

How to show only one instance of the Text file(.txt). Am I doing something wrong in my attempts? please suggest.

EDIT:

I want to open other text files afterwards but not the same and also the application should be accessible after opening a text file(or many). I have only one form.

  • 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-14T06:44:25+00:00Added an answer on June 14, 2026 at 6:44 am

    Create a dictionary at the form level:

    public Dictionary<string, Process> OpenedProcesses = new Dictionary<string, Process>(StringComparer.OrdinalIgnoreCase);
    

    Now change how you open the file (note the HasExited check – this is needed so that the user can close the Notepad and reopen it):

    // make sure that path is always in form C:\Folder\file.txt - less chance of different 
    // paths pointing to the same file.
    filePath = System.IO.Path.GetFullPath(filePath);
    
    Process proc;
    if (this.OpenedProcesses.TryGetValue(filePath, out proc) && !proc.HasExited)
    {
        MessageBox.Show("The file is already open!");
        // it could be possible to activate the window of the open process but that is another question on its own.
        return;
    }
    
    proc = System.Diagnostics.Process.Start(filePath);
    this.OpenedProcesses[filePath] = proc;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a multi-file patch for an open-source project, but the master
I have the following code where I am trying to open a text file.
I`m trying to return binary in webob.Response but error happens file = open(filePath, 'rb')
I'm trying to open an open source project and I'm getting an error when
I am using XCode 4.3.2 and trying to open an already existing project based
I am trying to use different open source apps in my project. Problem is
I'm trying to use an open-source project. Both the latest official (from a *.tar.gz
I am trying to modify an open source Forum called YetAnotherForum.net in the project
I am trying to generate a pdf at the click of a button in
Here is some code that I'm trying to make save some UITextView text. When

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.