RSS LOGORss   Welcome Guest  Login Register
Welcome to our Blogs
Back Back
Subject


mag
2008/06/09 02:35AM
How to Render SQL Report (Reporting Services) to PDF      Number of views: 1763

Below, you will find a code block that will convert the output report (generated from SharePoint List Items) into PDF file and it will be streamed to the user as "pdf" content type.

dsDocument.dtArchiveDocumentDataTable dt = new dsDocument.dtArchiveDocumentDataTable();
            SPSite site = SPContext.Current.Site;
            SPWeb web = site.RootWeb;
            SPList MOFDMSSearch = null;
            SPListItemCollection objSearchResults = null;
            SPQuery query = null;
            string enc = String.Empty;
            string mimetype = String.Empty;
            string ext = String.Empty;
            string devInfo = null;
            string[] streams;
            string strExt = string.Empty;
            Warning[] warnings = null ;
            byte[] byts;

             
            MOFDMSSearch = web.Lists[new Guid(Session["ListGuid"].ToString())];
            query = new SPQuery(MOFDMSSearch.Views[0]);//.Views[0]);
            query.Query = Session["CAMLQuery"].ToString();
            objSearchResults = MOFDMSSearch.GetItems(query);
            rptViewer.LocalReport.ReportPath = Server.MapPath("Reports/rptDocumentArchive.rdlc");
            ReportDataSource rds = new ReportDataSource();
            rds.Name = "dsDocument_dtArchiveDocument";
            dt.Load(MOFDMSDS.GetDataTable(objSearchResults).CreateDataReader());
            rds.Value = dt;
            dt.TableName = "dsDocument_dtArchiveDocument";
            rptViewer.LocalReport.DataSources.Add(rds);
            rptViewer.LocalReport.Refresh();
            rptViewer.LocalReport.ExecuteReportInCurrentAppDomain(System.Reflection.Assembly.GetExecutingAssembly().Evidence);
           
            byts= rptViewer.LocalReport.Render("PDF", devInfo, out mimetype, out enc, out strExt, out  streams, out  warnings);
            Response.ClearContent();
            Response.Clear ();
            Response.ContentType = "application/pdf";
            Response.OutputStream.Write(byts, 0, byts.Length);
            Response.Flush();
            Response.End();

 

Best wishes,

MAG