Download File via DirectEvent

  1. #1

    Download File via DirectEvent

    How would a file download that is initiated via a DirectEvent work in Ext.NET v7?

    This forum post 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
  2. #2
    Hello Paul!

    You probably want to check this forum thread: Download File using DirectEvent

    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!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    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
  4. #4
    Thanks for the feedback, Paul, glad it helped you find the best approach to solve the file download functionality!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Download File using DirectEvent
    By bbros in forum 7.x Classic Premium Help
    Replies: 1
    Last Post: Mar 10, 2021, 9:21 PM
  2. download file with DirectEvent on GridPanel
    By novacp in forum 2.x Help
    Replies: 1
    Last Post: Feb 13, 2014, 10:38 AM
  3. Download File using DirectEvent
    By Daniil in forum Examples and Extras
    Replies: 0
    Last Post: Dec 13, 2013, 4:02 AM
  4. [CLOSED] How to download a file in DirectEvent?
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Jun 08, 2012, 1:20 PM
  5. [CLOSED] [1.0] DirectEvent File Download
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Jan 21, 2011, 6:04 PM

Posting Permissions