Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opening a text file using process.start

Tags:

c#

i've been trying to open a text file from my system after computing pearson correlation and writing the result on a text file but so far for some reason the code doesn't open any notepad files i've tried opening other files and they work fine but .txt files are not opening specifically, even .docx files are opening using the same code! if anyone could please tell me if there is any specific reason for this! here is the line i'm writing in my code using process.start()

System.Diagnostics.Process.Start(@"C:\Users\Atif\Desktop\1.txt");

or

System.Diagnostics.Process.Start(Directory.GetCurrentDirectory()+"\\1.txt");

i think there's something wrong with my PC i just tried the same code on another machine and it is working! but i still don't understand what could be the problem apart from this program the notepad is working fine!

like image 993
Atif Avatar asked Mar 17 '23 23:03

Atif


2 Answers

if you want to use Notepad to open the file and it is not the default text editor you can use like following:

Process.Start("notepad.exe", @"C:\Users\Atif\Desktop\1.txt");
like image 132
apomene Avatar answered Mar 29 '23 08:03

apomene


I know this is old, but I had a similar issue with .Net 7.0 (worked in .Net 4.8.1)... I had to use:

ProcessStartInfo psi = new ProcessStartInfo(Filename);
psi.Verb = "open";
psi.UseShellExecute = true;
Process.Start(psi);
like image 35
Stephen Lee Parker Avatar answered Mar 29 '23 10:03

Stephen Lee Parker