How to bring up the “Windows cannot open this file

2019-04-08 23:03发布

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.

2条回答
放我归山
2楼-- · 2019-04-08 23:43

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();
查看更多
放荡不羁爱自由
3楼-- · 2019-04-08 23:44
Process pr = new Process();
pr.StartInfo.FileName = fileTempPath;
pr.StartInfo.ErrorDialog = true; // important
pr.Start();
查看更多
登录 后发表回答