Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to Process.Start()

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
}

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?

like image 484
ChrisFletcher Avatar asked Jan 14 '10 16:01

ChrisFletcher


2 Answers

You can check the registry to see if you have an application associated with that file type before calling Process.Start. Alternatively, you can catch the componentmodel exception and open the open with dialog from there.

like image 138
jmaresca Avatar answered Oct 26 '22 00:10

jmaresca


See this article for using the Open With dialog

http://www.codeproject.com/KB/shell/openwith.aspx

I would put the Process.Start call in a try statement, and then show the "Open With" in the catch.

like image 32
David Avatar answered Oct 26 '22 00:10

David