When trying to export data from DataGridView
to excel System.ComponentModel.Win32Exception: 'The specified executable is not a valid application for this OS platform.'
exception is thrown, funny thing is that file is saved like supposed to.
I fought that this is because I reinstalled packages for entire solution, but it's not the case.
Exception occurs when trying to call Process.Start(fileName)
method, where the value of fileName is: C:\\Users\\net\\Desktop\\Excel TESTING\\OperatorStatisticsData.xlsx
Note that my application is running on any CPU( 32 or 64 bit), and I am currently running win10 64 bit operating system. Any suggestion how to fix this?
Try to call
EXCEL.EXE
directly (change path if need to):UPDATE
You can obtain executable file by using Shell AssocQueryString function, which retrieves (amongst other properties) executable file associated with extension. Here's the method on C# which makes use of it:
Now we can retrieve executable file and open Excel file: