We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon
Starting in 2019, the Reporting control is no longer included in Essential Studio. If you're experiencing issues with the Syncfusion Reporting Platform, Report Viewer, Report Designer, or Report Writer, we recommend migrating to Bold Reports, our dedicated reporting platform.

Bold Reports offers a comprehensive suite of tools and features for all your reporting needs, and we will help you make a smooth transition from the discontinued control. Our support team at https://support.boldreports.com/ is here to assist you with any questions or difficulties you may encounter during the migration process.

We thank you for choosing Syncfusion and appreciate your understanding.

Designer override actions like save etc and show hide tools on condition

Hi Team,

I am using ReportViewer & ReportDesigner both in MVC5 project. I want to Override the actions on tools bars in both controls (i.e. Save: send created report to action methods to save on web server instead of download and dynamic load report to viewer by link provided from action method) and show/hide tools based on access rights, Is this possible? How? please provide code snippets.

Thanks and Regards,

Vikas Bare
vikas@eosuk.com

6 Replies

VS Vinoth Srinivasan Syncfusion Team August 30, 2019 11:52 AM UTC

Hi Simon, 
 
Thanks for your interest in Syncfusion components. 
 
Yes we can able to hide the older buttons and add the customized buttons in toolbar. Please find the below help documentation for your reference. 
 
We have added customization application in our online sample and please find the below link for your reference. 
 
Regards, 
Vinoth S. 



SM Simon Maystre September 26, 2019 12:31 PM UTC

Thank you for your reply. please provide solution for below requirements:

1) In MVC, On button click, I want to capture new created report file(.rdl)(From Designer) and send to WebAPI to save on web server instead of download and Save to report file on server.

2) In MVC, On button click/in backend, I want to capture viewer report/.rdl and create pdf and add to email as attachment.

Thanks and Regards.



VS Vinoth Srinivasan Syncfusion Team September 30, 2019 05:45 PM UTC

Hi Simon, 

Sorry for the delay. 

We will prepare sample for your requirement and update you the sample by 1st October 2019. 

Regards, 
Vinoth S. 



VS Vinoth Srinivasan Syncfusion Team October 1, 2019 09:29 AM UTC

Hi Simon, 
 
Thanks for your patience. 
 
Query 
Response 
1) In MVC, On button click, I want to capture new created report file(.rdl)(From Designer) and send to WebAPI to save on web server instead of download and Save to report file on server. 
We can able to customize saving of report using the SaveReportClick event in our Report Designer. So, you can save the report with your appropriate server using this event. Please find the below code snippet for your reference. 
 
<div style="width:100%; height:100%; position:absolute;"> 
        <input type="button" id="save" value="Save" onclick="clickSave"/> 
        @{Html.SF().ReportDesigner("designer").ServiceUrl("/api/DesignerAPI").Render();} 
    </div> 
    @(Html.SF().ScriptManager()) 
 
    <script type="text/javascript"> 
 
        $("#save").click(function () { 
            debugger; 
            var designer = $('#designer').data('ejReportDesigner'); 
            designer.model.saveReportClick = save(); 
        }); 
 
        function save() { 
            // Write your block of code  
            var designer = $('#designer').data('ejReportDesigner'); 
            designer.saveReport(); 
        }  
    </script> 
2) In MVC, On button click/in backend, I want to capture viewer report/.rdl and create pdf and add to email as attachment. 
Yes, we can able to create the PDF file when clicking the export button in Report viewer. Please find the below code example for how to create and attach the PDF file in Mail. 
public object PostReportAction(Dictionary<string, object> jsonResult) 
        { 
            if (jsonResult != null && jsonResult.ContainsKey("resourcetype")) 
            { 
                var _stream = ReportHelper.GetReport(jsonResult["controlID"].ToString(), "Html"); 
                _stream.Position = 0; 
                StreamReader _reader = new StreamReader(_stream); 
                var mailBody = _reader.ReadToEnd(); 
                mailBody = mailBody.Replace("<HTML>", "<html><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\" />"); 
                mailBody = mailBody.Replace("</HTML>", "<script>(function () {var rules = document.styleSheets[document.styleSheets.length - 1].rules;for (var idx = 0; idx < rules.length; idx++) {var elements = document.querySelectorAll(rules[idx].selectorText);for (var i = 0; i < elements.length; i++) {elements[i].style.cssText += rules[idx].style.cssText;}}var _length = rules.length;for (var i = 0; i < _length; i++) {document.styleSheets[document.styleSheets.length - 1].removeRule(0);}document.styleSheets[document.styleSheets.length - 1] = [];document.scripts[document.scripts.length - 1] = [];})();</script></html>"); 
                var t = new Thread(delegate () 
                { 
                    System.Windows.Forms.WebBrowser _webBrowser = new System.Windows.Forms.WebBrowser(); 
                    _webBrowser.DocumentText = mailBody; 
                    do 
                    { 
                        System.Windows.Forms.Application.DoEvents(); 
                        Thread.Sleep(500); 
                    } while (_webBrowser.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete || _webBrowser.IsBusy); 
                    mailBody = "<html><body>" + _webBrowser.Document.Body.InnerHtml + "</body></html>"; 
                }); 
 
                t.SetApartmentState(ApartmentState.STA); 
                t.Start(); 
                t.Join(); 
 
                var _PdfStream = ReportHelper.GetReport(jsonResult["controlID"].ToString(), "Pdf"); 
                _PdfStream.Position = 0; 
 
                var data = ReportHelper.GetResource(jsonResult["controlID"].ToString(), "Pdf", false); 
                this.SendMsg(_PdfStream, mailBody, jsonResult["reportName"].ToString()); 
            } 
            return ReportHelper.ProcessReport(jsonResult, this as IReportController); 
        } 
 
        public bool SendMsg(Stream str, string mailBody, string reportName) 
        { 
            try 
            { 
                MailMessage mail = new MailMessage(); 
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); 
                mail.IsBodyHtml = true; 
                mail.From = new MailAddress("test@gmail.com"); 
                mail.To.Add("test@syncfusion.com"); 
                mail.Subject = "Report_Name : " + reportName + " paramName : "; 
                str.Position = 0; 
                if (str != null) 
                { 
                    mail.Body = mailBody; 
                    ContentType ct = new ContentType(); 
                    ct.Name = "report" + DateTime.Now.ToString() + ".html"; 
                    System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(str, ct); 
                    mail.Attachments.Add(attachment); 
                } 
 
                SmtpServer.Port = 587; 
                SmtpServer.Credentials = new System.Net.NetworkCredential("test@gmail.com", "xxxxxxxx"); 
                SmtpServer.EnableSsl = true; 
                SmtpServer.Send(mail); 
                return true; 
            } 
            catch (Exception ex) 
            { 
                ex.ToString(); 
            } 
 
            return false; 
        } 
 
 
We have prepared the simple sample for your reference and it can be downloaded from below location. 
 
Regards, 
Vinoth S. 



SM Simon Maystre January 4, 2020 06:55 AM UTC

Hi Team,

The Query 1 still not giving desired output. As the default function of save button on Designer is to download report file, i want to override that instead of download get byte array in event and sent it to Web Api for further action. is this possible with this control? 

1) Is the save button event overridable in JS or MVC Controller ?
2) If Yes then in that event how to get Byte array/stream of report file in JS or Controller in MVC to save/post in desired location/API?


VS Vinoth Srinivasan Syncfusion Team January 7, 2020 10:23 AM UTC

Hi Simon, 
 
We cannot able to get the report as byte array directly when using our Report Designer control. But we can able to get the report as JSON or XML data then you can convert that data to byte array using your API controller. Please find the below code snippet to get the XML data from report when clicking the save button. 
 
<body> 
    <div style="width:100%; height:100%; position:absolute;"> 
        <input type="button" id="Save" value="Save Report" /> 
        @{Html.Bold().ReportDesigner("designer").ServiceUrl("/api/DesignerAPI").Render();} 
    </div> 
    @(Html.Bold().ScriptManager()) 
 
    <script type="text/javascript"> 
        $(document).ready(function () { 
            $("#Save").click(function () { 
                var designerObj = $("#designer").data("boldReportDesigner"); 
                designerObj.saveReportDefinition((any) => { saveXMLData(any) }, ej.ReportDesigner.DataFormat.XML); 
            }); 
        }); 
 
        function saveXMLData(XmlData) { 
            $.ajax({ 
                url: 'http://localhost:51897/api/DesignerAPI/GetByteArray', 
                type: 'POST', 
                contentType: 'text/xml', 
                data: XmlData, 
                success: function (data, textStatus, xhr) { 
                    alert("save button"); 
                }, 
                error: function (xhr, textStatus, errorThrown) { 
                    alert('Error in Operation'); 
                } 
            }); 
        } 
    </script> 
 
</body> 
 
 
Regards, 
Vinoth S. 


Loader.
Live Chat Icon For mobile
Up arrow icon