PDA

View Full Version : [CLOSED] Download File via DirectEvent



plok77
Jul 19, 2021, 12:00 PM
How would a file download that is initiated via a DirectEvent work in Ext.NET v7?

This forum post (https://forums.ext.net/showthread.php?27575-Download-File-using-DirectEvent) explains how it worked in a previous version. I can't find any 'IsUpload' property for a click event handler in v7 though. I assume things have changed somewhat in the framework since that post was written.

In the code-behind of a Razor page, I want to create a button that, when clicked, will invoke a Direct Event for the page. Something like this:


new Button
{
Text = "Export",
DirectEvents =
{
new ClickDirectEventHandler
{
Url = "ExportToExcel", // How to set page handler instead?
ExtraParams =
{
new DirectEventParameter
{
Key = "TabName",
Value = tabName
}
}
}
}
}

The handler for the Direct Event looks something like this:


[Direct]
public async Task<IActionResult> OnPostExportToExcelAsync([FromBody] ExcelExportData request)
{
byte[] fileContents = DoWorkToCreateExcelFile();

return File(
fileContents,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"MyFile.xslx");
}

Thanks

Paul

fabricio.murta
Jul 19, 2021, 1:26 PM
Hello Paul!

You probably want to check this forum thread: Download File using DirectEvent (https://forums.ext.net/showthread.php?63101)

We answered that very similar question some time ago and we still didn't receive a feedback from the one asking it, so it'd be appreciated if you can let us know if that helps or not, so we could improve the answer.

Hope this helps!

plok77
Jul 20, 2021, 7:59 AM
Fabricio

Yes, it did help. I ended up attaching a JavaScript listener to the button click event, and using the listener to trigger the submission of a HTML form element on the page that invoked the file download action of my Razor page. This worked OK, so no need to use a DirectEvent.

Regards

Paul

fabricio.murta
Jul 20, 2021, 8:36 PM
Thanks for the feedback, Paul, glad it helped you find the best approach to solve the file download functionality!