open a text file only if not opened alread (open in NotePad)

Posted by Mr_Green on Stack Overflow See other posts from Stack Overflow or by Mr_Green
Published on 2012-11-14T10:26:52Z Indexed on 2012/11/14 11:00 UTC
Read the original article Hit count: 194

Filed under:
|
|

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 Link , 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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms