Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Process.Start can not open a file based on the extension

If I write into the command prompt

c:\Data\a.xls
c:\Data\b.pdf
c:\Data\c.txt

then the corresponding files are opened with the default application. I could do the same from program.

Process.Start(@"c:\Data\a.xls");
Process.Start(@"c:\Data\b.pdf");
Process.Start(@"c:\Data\c.txt");

Unfortunately, this does not work anymore. I use windows 10 and .net7.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Process.Start("notepad.exe", @"c:\Data\c.txt"); // works
Process.Start("excel.exe", @"c:\Data\a.xls"); // does not work

If I provide the full path of excel.exe then it works. I would like to achieve the old functionality just to provide the filename and open it with the default application.

>Solution :

Set the UseShellExecute property to true.

The default is true on .NET Framework apps and false on .NET Core apps.

Also see StartInfo.


Download/install NuGet package: System.Diagnostics.Process

ProcessStartInfo startInfo = new ProcessStartInfo() { FileName= @"c:\Data\a.xls", UseShellExecute = true };
Process.Start(startInfo);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading