1

I have a link button as below:

 <asp:LinkButton ID="Import" runat="server" Font-Size="Small" Visible="true">Import</asp:LinkButton>

On click of this link button,I want the user to download a .exe file if it is not already present in user's computer or open the existing .exe file if it is already present in the user's computer.

I tried this:

string str = @"C:\Users\Documents\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe";
    Process process = new Process();
    process.StartInfo.FileName = str;
    process.Start();

This works fine in my local machine but the .exe cannot be accessed from the web page once its hosted.I think its possibly because of website security issues (correct me if I am wrong) that it doesn't allow the user to access the .exe location.

This was a little bit of background info.

My question is how do I modify this so that the user can download the .exe to his own machine (since I am not being able to access otherwise) and if he has done so once,the next time he clicks on the link button it opens his previously downloaded .exe ?

bishnu
  • 49
  • 1
  • 11

2 Answers2

2

If you want a user to download your application(.exe) you should include it in the web project, and the link should reference the file by a relative path.

A browser will never let a site run an .exe file (after it was downloaded), just by clicking a link, this is a big security risk.

Asal
  • 63
  • 7
  • Okay,so I included the .exe in my web project and changed the string to string str = "ConsoleApplication1.exe"; This doesn't work though.Is this what you were trying to convey ? The error I get is :"The system cannot find the file specified". Its in the same folder as the web project. – bishnu Jun 03 '15 at 08:52
  • I don't understand what you're trying to do. `Process.Start` will start the process *on the same machine that is executing that code*. You cannot use `Process.Start` to start anything on the user's computer *unless you execute that code on that computer*. Can you elaborate on what specifically you want to do, and drop the code that you have right now as this is more confusing than it answers any questions we have to your question. – Lasse V. Karlsen Jun 03 '15 at 09:55
  • I'm sorry for that. I want that on click of the link button the user can download the .exe file – bishnu Jun 03 '15 at 11:29
  • If you include the .exe file in the sln then the web server can access the file. Let's say it's in the root ("/") and then in the folder assets. The path of the link should look like this : "/assest/ConsoleApplication1.exe". – Asal Jun 04 '15 at 08:50
  • Indeed the Process.Start only works on the Web server you cannot do anything on the client machine from the code of the web server. If you wan to do something on the client machine you need to write that code in the "ConsoleApplication1.exe". Keep in mind even if the client downloads the file there will be no guarantee that the user will also execute that file. – Asal Jun 04 '15 at 08:53
0

How to launch an EXE from Web page (asp.net)

Refer this page. We faced similar problem and then agreed on below solution. On click allow it will be downloaded and option for running will come. This will be browser dependent.

Community
  • 1
  • 1
Mahesh Malpani
  • 1,782
  • 16
  • 27