views:

129

answers:

5

How would you launch a winform app from within an asp.net page?

A: 

If you really mean Winform, like your tag, rather than Webform, the answer is that you can't do it using just ASP, as that would be a significant security issue. You'd likely need an ActiveX control or similar.

phoebus
Sorry, yes, I meant Winforms. Fixed the title now.
Andrew
A: 

Convert the winform application you wish to embed to the more web-friendly Silverlight.

Gurdas Nijor
Thanks for the answer. However, I need to be able to communicate with the user's local installation of Outlook. Would that be possible through Silverlight?
Andrew
+1  A: 

As it was already said I don't think you can do it. What you can do is to post a link to your application (or its installation package) on your website and let user to download and run it. There are obvious problems with that, e.g. for any .net application you would need .net runtime of the proper version to be installed on user's machine.

As an alternative to what you're trying to do, pls, take a look at the ClickOnce Deployment documentation on msdn; this might be a solution to what you're trying to do

serge_gubenko
A: 

For security reasons, the web and Silverlight and flash don't allow you to directly interact with users file systems as that would make virus writing way to easy.

Of course, you can do anything you'd like with an ActiveX control, provided your users accept the control.

This site provides a tutorial on launching an app for a client:

<SCRIPT Language="JScript">
function runcmd() {
File="cmd.exe";
WSH=new ActiveXObject("WScript.Shell");
WSH.run(File);
}
</SCRIPT> 

<A href="#" onClick="runcmd(); return false;">Run CMD.exe</A>

Be aware that this will only work on IE and only after the user grants it access.

Why is it that you need to interact with the desktop application? Perhaps there's a better way to create this interaction.

Michael La Voie
I need it in order to interact with the user's local installation of Outlook. Specifically, to save emails into their drafts folder. I had tried doing this through WebDAV (to talk directly to the Exchange server), etc, but found that they did not quite meet my needs.
Andrew
I have tried your approach. It works when I use it on a plain html page. However, when I use it in my asp.net page it gives this error: "Automation server can't create object." Any idea what this means?
Andrew
UPDATE: I fixed the error by lowering IE's security setting to "Low".
Andrew
+3  A: 

If you have the ability to install the WinForm app up front, look at Application Protocol registration. It's described well by Mozilla here.

That would allow you to add a URL in your ASP.NET application along the lines of:

thing:SomethingThatThingUnderstands

Here's an example (from the page I linked to) of a URL link that would open OneNote:

<html>
<head>
<title>Test of onenote: application protocol</title>
</head>
<body>
<p>Open the
   <a href="onenote://C:\Program Files\Microsoft Office\Templates\1033\ONENOTE\12\Stationery\BLANK.ONE"> Notebook.</a></p>
</body>
</html>
Larsenal
Excellent! I haven't seen this before.
Michael La Voie
Is 'Application Protocol registration' IE8 only?
Jay Riggs
Nope. AFAIK, it's a Windows thing... rather than a browser thing. I've changed the link to go to a better page.
Larsenal