question

QamarMo-8446 avatar image
0 Votes"
QamarMo-8446 asked AgaveJoe edited

Download file and run it automatically immediately after download

How do I download a file and run it automatically immediately after download is completed?

dotnet-aspnet-generaldotnet-aspnet-webformsdotnet-aspnet-webpages
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AlbertKallal-4360 avatar image
0 Votes"
AlbertKallal-4360 answered QamarMo-8446 commented

You can't do that anymore.

At one time browsers did allow you to say click on a download link, and then choose run.

but, these days, for reasons of security, it not really possible - and this ability is controlled by the browser settings, and not your asp.net web site code.

It simply too high of a security risk. So, when you download a file?, then users will have to open their download folder, and choose run in most cases.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If I copy this .exe file on the server; how do I run it from a web page?

0 Votes 0 ·

I've tried using System.Diagnostics.ProcessStartInfo but it doesn't find the file FileName = @"MyExe.exe";

System.Diagnostics.ProcessStartInfo info = new ProcessStartInfo();
info.FileName = @"MyExe.exe";
info.Arguments = "";
info.WindowStyle = ProcessWindowStyle.Normal;
Process pro = Process.Start(info);
pro.WaitForExit();

0 Votes 0 ·
QamarMo-8446 avatar image
0 Votes"
QamarMo-8446 answered AgaveJoe converted comment to answer

I've got it to work... Here is the code.

             string toolsDir = System.Web.Hosting.HostingEnvironment.MapPath(ToolsDir);
             string toolexe = Path.Combine(toolsDir, ToolName);
             ProcessStartInfo psi = new ProcessStartInfo(toolexe);
             psi.WindowStyle = ProcessWindowStyle.Hidden;
             psi.CreateNoWindow = true;
             psi.Arguments = "-d:Dummy";
             Process p = Process.Start(psi);
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AgaveJoe avatar image
0 Votes"
AgaveJoe answered AgaveJoe edited

This design only works on your development machine because it is both the server and the client. Once deployed the code will execute on the server not the client machine.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.