JS Report Downloaded File - User Defined Names



  • Hello Sir,
    I Rendered html-xlsx and i am getting excel downloaded file with REPORT.xlsx default name. Instead of that i want to give dynamic User defined name to the downloaded file name. i used [ContentDisposition:"attachment, filename = "UserDefinedStaticFileName"], fine it is working, but i need user defined dynamic name - configurable report name in ASP .Net MVC. Can you please give me any solution for this.
    Thanking You Sir,
    YellaReddy P,
    Developer[ in AllCloud Enterprise Solutions Pvt Ltd]



  • Unfortunately you need override jsreport filter

    public class MyFilterAttribute : JsReportFilterAttribute
        {
            public MyFilterAttribute(IReportingService reportingService) : base(reportingService)
            {
            }
    
            protected override void AddResponseHeaders(ActionExecutedContext context, EnableJsReportAttribute jsreportAttribute, Report output)
            {
                foreach (var httpResponseHeader in output.Response.Headers)
                {
                    if (httpResponseHeader.Key.ToLower() == "connection" || httpResponseHeader.Key.ToLower() == "transfer-encoding")
                        continue;                
    
                    context.HttpContext.Response.AddHeader(httpResponseHeader.Key,
                                                           string.Join(";", httpResponseHeader.Value));
                }
    
                foreach (var httpContentHeader in output.Response.Content.Headers)
                {
                    if (httpContentHeader.Key.ToLower() == "content-disposition")
                    {
                        context.HttpContext.Response.AddHeader(httpContentHeader.Key,
                            (string)context.Controller.ViewData["jsreportCustomContentDisposition"]);
                    }
                    else
                    {
                        context.HttpContext.Response.AddHeader(httpContentHeader.Key,
                                                               string.Join(";", httpContentHeader.Value));
                    }
                }
    
                context.HttpContext.Response.ContentType = output.ContentType.MediaType;
            }
        }
    

    Register it instead of the original one

    filters.Add(new MyFilterAttribute(embeddedReportingServer.ReportingService));
    

    And set the content disposition dynamically.

    [EnableJsReport(Recipe = "phantom-pdf")]
            public ActionResult About()
            {
                ViewBag.jsreportCustomContentDisposition = "attachment; filename=myreport.pdf";
                return View();
            }
    


  • Thank you so much, nice, it is working as per my requirement.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.