MVC - Is it possible to save .mdc file in the viewer without it downloading

Stimulsoft Reports.WEB discussion
Post Reply
vapour.drops
Posts: 3
Joined: Thu Feb 07, 2019 7:49 am

MVC - Is it possible to save .mdc file in the viewer without it downloading

Post by vapour.drops »

Hello

I want to save an edited version of the mdc file from the viewer. I can see that with the save button I can enable it export documents, however I do not want it to download onto the client's machine. Is there a way to stop this? Or can i create a custom button in the toolbar which will return me the StiReport object?

Thanks
Lech Kulikowski
Posts: 6239
Joined: Tue Mar 20, 2018 5:34 am

Re: MVC - Is it possible to save .mdc file in the viewer without it downloading

Post by Lech Kulikowski »

Hello,

You can use the export event in which save the report as you needed:
https://www.stimulsoft.com/en/documenta ... export.htm

Thank you.
vapour.drops
Posts: 3
Joined: Thu Feb 07, 2019 7:49 am

Re: MVC - Is it possible to save .mdc file in the viewer without it downloading

Post by vapour.drops »

When i return StiMvcViewer.ExportReportResult(); this still exports/downloads the document to the client machine.

Code: Select all

   public ActionResult ExportReport(string filename)
        {
            StiReport report = StiMvcViewer.GetReportObject();

            var result = StiMvcViewer.ViewerEventResult();

            if (report != null)
            {
                if (!string.IsNullOrEmpty(filename))
                {
                    report.SaveDocument(filename);
                }
            }

         return StiMvcViewer.ExportReportResult();
        }
Also I only want the user to hit save and not need to select the one option in the dropdownlist (one too many clicks). Is this possible?
Thanks in advance
Lech Kulikowski
Posts: 6239
Joined: Tue Mar 20, 2018 5:34 am

Re: MVC - Is it possible to save .mdc file in the viewer without it downloading

Post by Lech Kulikowski »

Hello,

You need to redefine the postExport JavaScript method for the viewer component so as not to send a POST request when exporting a document. This can be done with the following code:
viewer:

Code: Select all

<script>
    jsMvcViewer._postExport = jsMvcViewer.postExport;
    jsMvcViewer.postExport = function (format, settings) {
        if (format == "Document") {
            var data = {
                action: "ExportReport",
                exportFormat: format,
                exportSettings: settings
            };

            jsMvcViewer.postAjax(jsMvcViewer.options.requestUrl.replace("{action}", jsMvcViewer.options.actions.exportReport), data, jsMvcViewer.postExportDone);
        }
        else {
            jsMvcViewer._postExport(format, settings);
        }
    }

    jsMvcViewer.postExportDone = function (data) {
        alert("The document file is saved, the server returned: " + data);
    }
</script>
Controller:

Code: Select all

public ActionResult ExportReport()
{
    var requestParams = StiMvcViewer.GetRequestParams();
    var report = StiMvcViewer.GetReportObject();
    if (requestParams.ExportFormat == StiExportFormat.Document && report != null)
    {
        //report.SaveDocument(filename);
        return Content("SaveOK");
    }
            
    return StiMvcViewer.ExportReportResult();
}
Thank you.
vapour.drops
Posts: 3
Joined: Thu Feb 07, 2019 7:49 am

Re: MVC - Is it possible to save .mdc file in the viewer without it downloading

Post by vapour.drops »

Great thank you that worked however it was still 2 clicks to save one format (mdf) option. In the end we needed to save the mdc file from a button external to the viewer.
Lech Kulikowski
Posts: 6239
Joined: Tue Mar 20, 2018 5:34 am

Re: MVC - Is it possible to save .mdc file in the viewer without it downloading

Post by Lech Kulikowski »

Hello,

You can call saving in MDC format with the following JavaScript method:
jsMvcViewer.postExport("Document", jsMvcViewer.getDefaultExportSettings("Document"));

Thank you.
Post Reply