No application associated with the specified file exception

UnhandledException: System.ComponentModel.Win32Exception: No application is associated with the specified file for this operation at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start(String fileName) 

Hello to all,

I get the following exception on one computer, which I test when I try to use Process.Start to open a CSV file. I think this is happening because no association of .csv files has been set in this field.

So how would you avoid this situation?

Run the process. Will the start open in Notepad? - Ideally, this should be open in excel, but what do you do if excel then does not exist on this computer?

thanks

+6
c # exception-handling process.start notepad win32exception
source share
3 answers

If your application depends on the fact that Excel was installed for the correct and effective work, then inform the user about it. Catch the exception and pull out a notification to inform them of the problem, but then in this notification give them the opportunity to open it in an alternative editor such as notepad.

It all boils down to a good UX - let the user know, but do it in such a way that you provide them with opportunities, offering options to continue, and not just stop them and stop when such a small problem arises.

Edit: Do what you do, do not assume that they have Excel, they may have another editor / editor such as OpenOffice. No matter what is registered in csv, let it do it. Do not try to go and check the file association yourself, your application cannot (possibly, will not) have sufficient privileges to go in the background in the registry.

You also need to check for other obvious causes of exceptions, for example, the user does not have permission to open the target file, this may be due to restrictions set in the folder or the file itself. The file may have been locked because it is still open in another process. There are many reasons why your Process.Start may fail.

Catch the exception, and if the reason is not the application associated with the file, offer them an option. If the user decides to use Notepad, try opening the file in Notepad, but don't forget about the exceptions. Notepad is a good option, it does not contain a file lock, but it still depends on the ACL in the folder / file.

+4
source share

If you set ProcessStartInfo.ErrorDialog = true, then the user will be prompted to enter the standard Windows dialog box: see here

+3
source share

Read the registry to see if there is a program associated with the file extension before you execute process.start. See HKEY_CLASSES_ROOT\.csv to find out who is registered to handle this file extension, if any.

+2
source share

All Articles