Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WebApplication.SendFile question
putting the code in a buttons AsyncClick-event the 4 parameter with the filename is ignored. This can be reproduced with the DownloadFromCache sample project. 
procedure TIWForm23.btnDownloadAsyncClick(Sender: TObject;
  EventParams: TStringList);
  WebApplication.SendFile(gSC.CacheDir + FFileName, True, FContentType, 'SampleFile.txt');

In mine real time app I've code where after a SendFile in the browser appears the hourglass and hangs when the same code is executed from the click-event, but works fine from the AsyncClick-event. But the AsyncClick has above problem ignoring the filename.
IW15.1.0 Evaluation, Delphi Rio 10.3.1
The hour glass is because your IWForm has property LockOnSubmit = True. Set it to false and it will work.
(08-01-2019, 09:08 AM)Alexandre Machado Wrote: The hour glass is because your IWForm has property LockOnSubmit = True. Set it to false and it will work.

This AsyncClick Button-> WebApplication.SendFile('C:\temp\test.pdf', true, '', '');  work in Chrome. Smile

Not work IE11? Sad
SendFile works in all browsers. It is probably being blocked by a popup blocker, no?

SendFile() during Async calls is not good idea, IMO.
First: it doesn't make any difference in terms of page loading times, flicker, etc. Actually the sync event is more straightforward than the Async event.
Second: the browser "understands" a OnClick event which opens a popup window as a direct action of the user, so almost everything is allowed (including opening a popup window).
On the other hand, an async event is not a direct user action: the Async event generates a XMLHttpRequest (Ajax) to the server, which responds with JavaScript which then tries to open a popup window. This is - in general - forbidden by browsers, by default, which causes it to fail.

So, in short:

- OnClick = Sync = direct user action -> browser allows it to open popups
- OnAsyncClic = Async/Ajax = user action triggers JavaScript code -> browser doesn't allow it to open popups

Forum Jump:

Users browsing this thread: 1 Guest(s)