Results 1 to 2 of 2

Thread: how to print PDF automatically without opening/saving file using ssrs in

  1. #1
    Join Date
    Apr 2012

    how to print PDF automatically without opening/saving file using ssrs in

    I want to open PDF File directly without prompting Open/Save in browser else I wish to show PDF in print preview and then print. The following is the code used to generate PDF file and works fine.

    string strReportName = string.Empty;
    if (Request.QueryString["ReportName"] != null)
    strReportName = Request.QueryString["ReportName"].ToString();
    HttpContext context = HttpContext.Current;
    if (!context.Response.Buffer)
    Warning[] warnings;
    string[] streamids;
    string mimeType;
    string encoding;
    string extension;
    //ReportServerURL returns me the URL of ReportServer
    string strReportUrl = ConfigurationManager.AppSettings["ReportServerURL"].ToString();
    //ReportFolder returns the path of Report Folder Name
    string strReportFolder = ConfigurationManager.AppSettings["ReportFolder"].ToString();
    ReportViewer rptViewer = new ReportViewer();
    rptViewer.ServerReport.ReportServerUrl = new System.Uri(strReportUrl);
    rptViewer.ServerReport.ReportPath = "/" + strReportFolder + strReportName;
    rptViewer.ServerReport.SetParameters(GetObjParameter(Request.QueryString["Parameters"], Request.QueryString["ParamValues"]));
    byte[] pdfContent = rptViewer.ServerReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
    context.Response.Buffer = true;
    context.Response.ContentType = "application/pdf";
    context.Response.AddHeader("Content-disposition", string.Format("attachment; filename={0}.{1}", strReportName, extension));
    A Generic Method for creating Dynamic Report Parameters is as follows: 
     private ReportParameter[] GetObjParameter(string Parameters, string Values)
                ReportParameter[] rptParams = null;
                string[] sParam = Parameters.Split(',');
                string[] sVal = Values.Split(',');
                if (sParam.Count() == sVal.Count())
                    rptParams = new ReportParameter[sParam.Count()];
                    for (int i = 0; i < sParam.Count(); i++)
                        if (sParam[i] == "FromDate" && sVal[i] == " 1/1/0001 12:00:00 AM")
                            sVal[i] = null;
                        if (sParam[i] == "ToDate" && sVal[i] == "1/1/0001 12:00:00 AM")
                            sVal[i] = null;
                        if (sParam[i] == "ETADate" && sVal[i] == "1/1/0001 12:00:00 AM")
                            sVal[i] = null;
                        rptParams[i] = new ReportParameter(sParam[i].ToString(), sVal[i]);
                return rptParams;
    Any Help would be appreciatable.

    Thanks in Advance

  2. #2
    Join Date
    May 2015
    One of the options is to use a separate library or API for that, for example, with FolderMill. Here are the details:

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts