Search code examples
c#stimulsoft

how to set export file name for a report in stimulsoft?


I make a report in Stimulsoft by using Stiwebviewer I show it in aspx file. Now I want to set Report filename that used in export, for example when I export the report to pdf...default name is Report(1).pdf.And I want to change it to Sedi.pdf.
I try this:

StiWebViewer1.ServerReportName = "Sedi";

But it did not work.


Solution

  • string reportName = "";
    protected void Page_Load(object sender, EventArgs e)
        {
            this.Mainreport = (StiReport)Session["SelectedReport"];
            this.reportName = (string)Session["ReportName"];
            StiWebViewer1.Report = this.Mainreport;
            StiWebViewer1.DataBind();
            if (!IsPostBack)
            {
                string iQueryString = Request.QueryString["sti_StiWebViewer1_export"];
                if (iQueryString != null) this.SaveFile(iQueryString);
            }
        }
        private void SaveFile(string iQueryString)
        {
            if (this.reportName == null) this.reportName = "Report";
            MemoryStream mes = new MemoryStream();
            HttpContext.Current.Response.Clear();
            switch (iQueryString)
            {
                #region Cases
                case "SaveAdobePdf":
                    {
                        this.Mainreport.ExportDocument(StiExportFormat.Pdf, mes);
                        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + this.reportName + ".Pdf");
                    }
                    break;
                case "SaveMicrosoftXps":
                    {
                        this.Mainreport.ExportDocument(StiExportFormat.Xps, mes);
                        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + this.reportName + ".Xps");
                    }
                    break;
                    #endregion
            }
            mes.WriteTo(Response.OutputStream);
            HttpContext.Current.Response.End();
            mes.Close();
        }