5

My users can attach documents to various entities in the application. Of course, if user A attaches a .TIFF file, user B may not have a viewer for that type of file.

So I'd like to be able to bring up this dialog:

alt text http://www.angryhacker.com/toys/cannotopen.png

My application is C# with VS2005.
Currently I do Process.Start and pass in the file name. If no association is found, it throws an exception.

AngryHacker
  • 59,598
  • 102
  • 325
  • 594

2 Answers2

15
Process pr = new Process();
pr.StartInfo.FileName = fileTempPath;
pr.StartInfo.ErrorDialog = true; // important
pr.Start();
Tim M.
  • 53,671
  • 14
  • 120
  • 163
user199539
  • 151
  • 1
  • 2
7

This should do it:

System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "rundll32.exe";
p.StartInfo.Arguments = "shell32.dll,OpenAs_RunDLL " + yourFileFullnameHere;

p.Start();
Jay Riggs
  • 53,046
  • 9
  • 139
  • 151
  • The problem with this approach is that it brings up the dialog box every time. I guess I should just execute this code if I get a Win32Exception stating that there is no association. – AngryHacker May 19 '09 at 18:00
  • Note that `OpenAs_RunDLL` is undocumented and [does not always work.](http://stackoverflow.com/questions/23566667/rundll32-shell32-dll) – Harry Johnston May 10 '14 at 01:41