问题描述
我刚刚完成了文档存储解决方案的编码,遇到了以下问题.在用户界面内,用户可以按一个按钮来打开文件:
I'm just finishing off coding a a document storage solution and I've run across the following issue. Within the UI the user can press a button to open a file:
try
{
Process.Start(file);
}
catch (Exception ex)
{
//Error handling code
}
我的问题是,如果用户没有与文件类型关联的应用程序,则会抛出componentmodel异常并显示一条消息.
My issue is that if the user has no application associated with the file type a componentmodel exception is thrown with a message to that effect.
我想做的是在这种情况下弹出打开方式"对话框,我是否缺少方法调用?
What I'd rather do is have the "Open with" dialog pop-up in that situation, is there a method call I'm missing?
推荐答案
有关使用打开方式"对话框的信息,请参见本文
See this article for using the Open With dialog
http://www.codeproject.com/KB/shell/openwith.aspx
我将把Process.Start调用放在try语句中,然后在捕获中显示打开方式".
I would put the Process.Start call in a try statement, and then show the "Open With" in the catch.
这篇关于替代Process.Start()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!