views:

94

answers:

3

Hi,

I'm putting together a C# winforms application, and it would be good to be able to have the ability for someone to click on a webpage link that automatically maximizes my c# application and passes some data to it. Pretty much like I see some webpages have a song link that automatically opens iTunes, and then in iTunes it searches for the song details you passed.

Q1 - How does one do this in HTML/Javascript?

Q2 - Does this approach only work on certain browsers?

Q3 - Would this only work on Windows? (I just need it for windows myself)

Thanks

+1  A: 

You would have to associate a new file type with your C# application. The web page could "launch" such a file by downloading it.

I believe you'd have to pass parameters by writing them to the file to be downloaded.


It's true that there would be a "run or save" prompt, but aside from that, I think this would be the simplest method, and the one that would be easiest to maintain.

John Saunders
A: 

My first reaction would be that you'd have to create some kind of browser plugin first, that would act as the middle man between your javascript and your C# application. This is because website javascript and other code is run in a limited security context and cannot access priviliged resources, such as other applications, named pipes, tcp ports, etc.

Aviad P.
did you see the response from tyranid? this sounds potentially simpler?
Greg
Yes, and more general, i.e. browser independent.
Aviad P.
+2  A: 

You can register a URL protocol handler (see) which allows you specify a unique URL protocol and you can make clickable links in web pages which will spawn a new application passing the complete URL. Be careful though because this mechanism has been mis-implemented a number of times which can expose you to exploitation.

Also browsers will normally warn you if you are trying to use one of these odd URLs. And this will only work on Windows (but there are alternatives on other OSes).

tyranid
thanks - so I guess the idea is that you build your C# winforms installation to perform this as part of the installation? (i.e. registering a protocol handler)
Greg
would this approach actually only work when the winforms app is not yet opened? That is, what if it is already opened?
Greg
You would need to implement some form of single instance application support so starting the new instance will actually cause the original to activate. There are plenty of examples on the net and it has been asked often on SO.
tyranid