How to bring up the “Windows cannot open this file” dialog?

寵の児 提交于 2019-12-06 02:42:14

问题


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.


回答1:


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();



回答2:


Process pr = new Process();
pr.StartInfo.FileName = fileTempPath;
pr.StartInfo.ErrorDialog = true; // important
pr.Start();


来源:https://stackoverflow.com/questions/884012/how-to-bring-up-the-windows-cannot-open-this-file-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!