Reputation: 3007
After creating an Excel file (*.xlsx
) programmatically, I would like to open it using the default system application for *.xlsx
files.
Problems are,
*.xlsx
files. Considering, normally user can set default applications to open a specific file in Windows (version 7, 8 or 8.1)*.xlsx
file.This question can also be generalized as to open any file using the default applications set for it in windows system and give a message to the user in case there isn't any applications that can open this file on the local system.
Upvotes: 0
Views: 3781
Reputation: 125748
Use Process.Start
, and it will automatically open in the default application for that file extension. You'll find it in System.Diagnostics
.
ProcessStartInfo startInfo = new ProcessStartInfo("C:\\SomePath\Test.xlsx");
Process.Start(startInfo);
As far as the second problem, there's no way to do that reliably. If you were sure the default application was Excel, you could use the Interop libraries to do so via COM, but there's no way to tell if the alternative default application supports that (or any other way of interop).
Upvotes: 3
Reputation: 4104
Can't you just use Process.Start(myFile.xlsx)? It'll basically just try to tell Windows decide what to do with it.
edit; Heh, darn- beaten by a few seconds. His answer is way more helpful!
Upvotes: 0