No application is associated with the specified file exception

baron picture baron · Apr 14, 2010 · Viewed 18.2k times · Source
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)

Hi everyone,

I am getting the following exception on one machine I am testing on when trying to use Process.Start to open a .csv file. I think this is happening because no file association has been set for .csv files on this box.

So how would you avoid this situation?

Force the Process.Start to open in Notepad? - Ideally it should be opened in excel, but what do you do if excel then doesn't exist on that computer?

Thanks

Answer

AZ. picture AZ. · Jun 7, 2012

If you set the ProcessStartInfo.ErrorDialog = true, then the user will be prompt with a standard windows dialog: see here