locked
Export RDLC Report/File To PDF Without Opening Preview/ReportViewer Page. RRS feed

  • Question

  • User-1818936033 posted

    Hi All.

    is it possible to export rdlc report/file to PDF/Excel without opening the reportviewer page.

    I mean, insert button in aspx page. When we click the button, system auto export rdlc report/file to PDF file.

    Anyone can help

    Tuesday, April 28, 2015 4:12 AM

Answers

  • User-1392847221 posted

    Yes It is possible

     LocalReport report = new LocalReport();
        report.ReportPath = "Report1.rdlc";
        ReportDataSource rds = new ReportDataSource();
        rds.Name = "DataSet1";//This refers to the dataset name in the RDLC file
        rds.Value = EmployeeRepository.GetAllEmployees();
        report.DataSources.Add(rds);
        Byte[] mybytes = report.Render("WORD");
        //Byte[] mybytes = report.Render("PDF"); for exporting to PDF
        using (FileStream fs = File.Create(@"D:\SalSlip.doc"))
        {
            fs.Write(mybytes, 0, mybytes.Length);
        }

    similar post

    http://forums.asp.net/t/1556522.aspx?RDLC+Export+directly+to+Excel+or+PDF+from+codebehind

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 28, 2015 10:29 AM
  • User-1818936033 posted

    My completed working code:

            Dim ECIR_No As String = Request.QueryString("ECIR_No")
    
            Dim report As New LocalReport()
    
            report.ReportPath = "1_ECIR_ItemToPrint_Details_ECI2.rdlc"
    
            Dim rds As New ReportDataSource()
            rds.Name = "DataSet_ECIR"
    
            Dim sqltext As String
    
            sqltext = ""
            sqltext = sqltext & " SELECT UserProfile.employee_name, ECIR.ECIR_No, ECIR.ECIR_ReqDept, ECIR.ECIR_RequestTypeDesc, ECIR.ECIR_ChangeSubject, ECIR.ECIR_Process, ECIR.ECIR_Product, ECIR.ECIR_Purpose, ECIR.ECIR_SummaryBefore, ECIR.ECIR_SummaryAfter, ECIR.ECIR_Change, ECIR.ECIR_NeedSBR, ECIR.ECIR_Reason, ECIR.ECIR_SBRNo, CONVERT(VARCHAR(10), ECIR.ECIR_DateRun, 103) AS ECIR_DateRun, ECIR.ECIR_SBRReqName, ECIR.ECIR_SBRReqDept, ECIR.ECIR_Summary, CONVERT(VARCHAR(10), ECIR.ECIR_ReviewDate, 103) AS ECIR_ReviewDate, ECIR.ECIR_Approval_REQHOD_Name, ECIR.ECIR_Approval_REQHOD_Approval, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_REQHOD_Date, 103) AS ECIR_Approval_REQHOD_Date, ECIR.ECIR_Approval_DHName_1, ECIR.ECIR_Approval_DHApproval_1, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate_1, 103) AS ECIR_Approval_DHDate_1, ECIR.ECIR_Approval_DHName_2, ECIR.ECIR_Approval_DHApproval_2, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate_2, 103) AS ECIR_Approval_DHDate_2, ECIR.ECIR_Approval_DHName_3, ECIR.ECIR_Approval_DHApproval_3, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate_3, 103) AS ECIR_Approval_DHDate_3, ECIR.ECIR_Approval_DHName_4, ECIR.ECIR_Approval_DHApproval_4, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate_4, 103) AS ECIR_Approval_DHDate_4, ECIR.ECIR_Approval_DHName_5, ECIR.ECIR_Approval_DHApproval_5, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate_5, 103) AS ECIR_Approval_DHDate_5, ECIR.ECIR_Approval_DHName_6, ECIR.ECIR_Approval_DHApproval_6, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate_6, 103) AS ECIR_Approval_DHDate_6, CONVERT(VARCHAR(10), ECIR.ECIR_ECIEffectiveDate, 103) AS ECIR_ECIEffectiveDate, ECIR.ECIR_Approval_DHName2_1, ECIR.ECIR_Approval_DHApproval2_1, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate2_1, 103) AS ECIR_Approval_DHDate2_1, ECIR.ECIR_Approval_DHName2_2, ECIR.ECIR_Approval_DHApproval2_2, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate2_2, 103) AS ECIR_Approval_DHDate2_2, ECIR.ECIR_Approval_DHName2_3, ECIR.ECIR_Approval_DHApproval2_3, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate2_3, 103) AS ECIR_Approval_DHDate2_3, ECIR.ECIR_Approval_DHName2_4, ECIR.ECIR_Approval_DHApproval2_4, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate2_4, 103) AS ECIR_Approval_DHDate2_4, ECIR.ECIR_Approval_DHName2_5, ECIR.ECIR_Approval_DHApproval2_5, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate2_5, 103) AS ECIR_Approval_DHDate2_5, ECIR.ECIR_Approval_DHName2_6, ECIR.ECIR_Approval_DHApproval2_6, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate2_6, 103) AS ECIR_Approval_DHDate2_6, ECIR.ECIR_Approval_DHRemarks2_6, CONVERT(VARCHAR(10), ECIR.ECIR_ECNEffectiveDate, 103) AS ECIR_ECNEffectiveDate, CONVERT(VARCHAR(10), ECIR.ECIR_DateCreated, 103) AS ECIR_DateCreated, ECIR.ECIR_Summary_1, ECIR.ECIR_Summary_2, ECIR.ECIR_Summary_3, ECIR.ECIR_Summary_4, ECIR.ECIR_Summary_5, ECIR.ECIR_Summary_6, ECIR.ECIR_Summary_7, ECIR.ECIR_Summary_8, ECIR.ECIR_Summary_9, ECIR.ECIR_Summary_10, ECIR.ECIR_AttachmentSummary_Details_1, ECIR.ECIR_AttachmentSummary_PIC_1, ECIR.ECIR_AttachmentSummary_ECD_1, ECIR.ECIR_AttachmentSummary_Details_2, ECIR.ECIR_AttachmentSummary_PIC_2, ECIR.ECIR_AttachmentSummary_ECD_2, ECIR.ECIR_AttachmentSummary_Details_3, ECIR.ECIR_AttachmentSummary_PIC_3, ECIR.ECIR_AttachmentSummary_ECD_3, ECIR.ECIR_AttachmentSummary_Details_4, ECIR.ECIR_AttachmentSummary_PIC_4, ECIR.ECIR_AttachmentSummary_ECD_4, ECIR.ECIR_AttachmentSummary_Details_5, ECIR.ECIR_AttachmentSummary_PIC_5, ECIR.ECIR_AttachmentSummary_ECD_5, ECIR.ECIR_AttachmentSummary_Details_6, ECIR.ECIR_AttachmentSummary_PIC_6, ECIR.ECIR_AttachmentSummary_ECD_6, ECIR.ECIR_AttachmentSummary_Details_7, ECIR.ECIR_AttachmentSummary_PIC_7, ECIR.ECIR_AttachmentSummary_ECD_7, ECIR.ECIR_AttachmentSummary_Details_8, ECIR.ECIR_AttachmentSummary_PIC_8, ECIR.ECIR_AttachmentSummary_ECD_8, ECIR.ECIR_AttachmentSummary_Details_9, ECIR.ECIR_AttachmentSummary_PIC_9, ECIR.ECIR_AttachmentSummary_ECD_9, ECIR.ECIR_AttachmentSummary_Details_10, ECIR.ECIR_AttachmentSummary_PIC_10, ECIR.ECIR_AttachmentSummary_ECD_10, ECIR.ECIR_Approval_DHName_7, ECIR.ECIR_Approval_DHApproval_7, ECIR.ECIR_Approval_DHName2_7, ECIR.ECIR_Approval_DHApproval2_7, CONVERT (VARCHAR(10), ECIR.ECIR_Approval_DHDate_7, 103) AS ECIR_Approval_DHDate_7, CONVERT (VARCHAR(10), ECIR.ECIR_Approval_DHDate2_7, 103) AS ECIR_Approval_DHDate2_7       "
            sqltext = sqltext & " FROM UserProfile INNER JOIN ECIR ON UserProfile.employee_no = ECIR.ECIR_ReqEmpNo"
            sqltext = sqltext & "  WHERE ECIR.ECIR_No = '" & ECIR_No & "'"
    
            Dim dsCustomers As DataSet_ECIR = GetData(sqltext)
    
            rds.Value = dsCustomers.Tables(0)
    
            report.DataSources.Add(rds)
    
    
            Dim mybytes As [Byte]() = report.Render("PDF")
            'Byte[] mybytes = report.Render("PDF"); for exporting to PDF
            Using fs As FileStream = File.Create("\\FUJIWEB\wwwroot\ECRSBRTEST2\ECIRAttachment\" & ECIR_No & ".pdf")
                fs.Write(mybytes, 0, mybytes.Length)
            End Using

    Private Function GetData(query As String) As DataSet_ECIR
    
            Dim connectionString As String = ConfigurationManager.ConnectionStrings("OESConnectionString").ConnectionString
    
            Dim cmd As New SqlCommand(query)
    
            Using con As New SqlConnection(connectionString)
    
                Using sda As New SqlDataAdapter()
    
                    cmd.Connection = con
    
                    sda.SelectCommand = cmd
    
                    Using dsCustomers As New DataSet_ECIR()
    
                        sda.Fill(dsCustomers, "ECIR")
    
                        Return dsCustomers
    
                    End Using
    
                End Using
    
            End Using
    
        End Function

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 28, 2015 11:32 PM

All replies

  • User-1392847221 posted

    Yes It is possible

     LocalReport report = new LocalReport();
        report.ReportPath = "Report1.rdlc";
        ReportDataSource rds = new ReportDataSource();
        rds.Name = "DataSet1";//This refers to the dataset name in the RDLC file
        rds.Value = EmployeeRepository.GetAllEmployees();
        report.DataSources.Add(rds);
        Byte[] mybytes = report.Render("WORD");
        //Byte[] mybytes = report.Render("PDF"); for exporting to PDF
        using (FileStream fs = File.Create(@"D:\SalSlip.doc"))
        {
            fs.Write(mybytes, 0, mybytes.Length);
        }

    similar post

    http://forums.asp.net/t/1556522.aspx?RDLC+Export+directly+to+Excel+or+PDF+from+codebehind

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 28, 2015 10:29 AM
  • User-1818936033 posted

    My completed working code:

            Dim ECIR_No As String = Request.QueryString("ECIR_No")
    
            Dim report As New LocalReport()
    
            report.ReportPath = "1_ECIR_ItemToPrint_Details_ECI2.rdlc"
    
            Dim rds As New ReportDataSource()
            rds.Name = "DataSet_ECIR"
    
            Dim sqltext As String
    
            sqltext = ""
            sqltext = sqltext & " SELECT UserProfile.employee_name, ECIR.ECIR_No, ECIR.ECIR_ReqDept, ECIR.ECIR_RequestTypeDesc, ECIR.ECIR_ChangeSubject, ECIR.ECIR_Process, ECIR.ECIR_Product, ECIR.ECIR_Purpose, ECIR.ECIR_SummaryBefore, ECIR.ECIR_SummaryAfter, ECIR.ECIR_Change, ECIR.ECIR_NeedSBR, ECIR.ECIR_Reason, ECIR.ECIR_SBRNo, CONVERT(VARCHAR(10), ECIR.ECIR_DateRun, 103) AS ECIR_DateRun, ECIR.ECIR_SBRReqName, ECIR.ECIR_SBRReqDept, ECIR.ECIR_Summary, CONVERT(VARCHAR(10), ECIR.ECIR_ReviewDate, 103) AS ECIR_ReviewDate, ECIR.ECIR_Approval_REQHOD_Name, ECIR.ECIR_Approval_REQHOD_Approval, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_REQHOD_Date, 103) AS ECIR_Approval_REQHOD_Date, ECIR.ECIR_Approval_DHName_1, ECIR.ECIR_Approval_DHApproval_1, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate_1, 103) AS ECIR_Approval_DHDate_1, ECIR.ECIR_Approval_DHName_2, ECIR.ECIR_Approval_DHApproval_2, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate_2, 103) AS ECIR_Approval_DHDate_2, ECIR.ECIR_Approval_DHName_3, ECIR.ECIR_Approval_DHApproval_3, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate_3, 103) AS ECIR_Approval_DHDate_3, ECIR.ECIR_Approval_DHName_4, ECIR.ECIR_Approval_DHApproval_4, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate_4, 103) AS ECIR_Approval_DHDate_4, ECIR.ECIR_Approval_DHName_5, ECIR.ECIR_Approval_DHApproval_5, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate_5, 103) AS ECIR_Approval_DHDate_5, ECIR.ECIR_Approval_DHName_6, ECIR.ECIR_Approval_DHApproval_6, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate_6, 103) AS ECIR_Approval_DHDate_6, CONVERT(VARCHAR(10), ECIR.ECIR_ECIEffectiveDate, 103) AS ECIR_ECIEffectiveDate, ECIR.ECIR_Approval_DHName2_1, ECIR.ECIR_Approval_DHApproval2_1, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate2_1, 103) AS ECIR_Approval_DHDate2_1, ECIR.ECIR_Approval_DHName2_2, ECIR.ECIR_Approval_DHApproval2_2, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate2_2, 103) AS ECIR_Approval_DHDate2_2, ECIR.ECIR_Approval_DHName2_3, ECIR.ECIR_Approval_DHApproval2_3, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate2_3, 103) AS ECIR_Approval_DHDate2_3, ECIR.ECIR_Approval_DHName2_4, ECIR.ECIR_Approval_DHApproval2_4, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate2_4, 103) AS ECIR_Approval_DHDate2_4, ECIR.ECIR_Approval_DHName2_5, ECIR.ECIR_Approval_DHApproval2_5, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate2_5, 103) AS ECIR_Approval_DHDate2_5, ECIR.ECIR_Approval_DHName2_6, ECIR.ECIR_Approval_DHApproval2_6, CONVERT(VARCHAR(10), ECIR.ECIR_Approval_DHDate2_6, 103) AS ECIR_Approval_DHDate2_6, ECIR.ECIR_Approval_DHRemarks2_6, CONVERT(VARCHAR(10), ECIR.ECIR_ECNEffectiveDate, 103) AS ECIR_ECNEffectiveDate, CONVERT(VARCHAR(10), ECIR.ECIR_DateCreated, 103) AS ECIR_DateCreated, ECIR.ECIR_Summary_1, ECIR.ECIR_Summary_2, ECIR.ECIR_Summary_3, ECIR.ECIR_Summary_4, ECIR.ECIR_Summary_5, ECIR.ECIR_Summary_6, ECIR.ECIR_Summary_7, ECIR.ECIR_Summary_8, ECIR.ECIR_Summary_9, ECIR.ECIR_Summary_10, ECIR.ECIR_AttachmentSummary_Details_1, ECIR.ECIR_AttachmentSummary_PIC_1, ECIR.ECIR_AttachmentSummary_ECD_1, ECIR.ECIR_AttachmentSummary_Details_2, ECIR.ECIR_AttachmentSummary_PIC_2, ECIR.ECIR_AttachmentSummary_ECD_2, ECIR.ECIR_AttachmentSummary_Details_3, ECIR.ECIR_AttachmentSummary_PIC_3, ECIR.ECIR_AttachmentSummary_ECD_3, ECIR.ECIR_AttachmentSummary_Details_4, ECIR.ECIR_AttachmentSummary_PIC_4, ECIR.ECIR_AttachmentSummary_ECD_4, ECIR.ECIR_AttachmentSummary_Details_5, ECIR.ECIR_AttachmentSummary_PIC_5, ECIR.ECIR_AttachmentSummary_ECD_5, ECIR.ECIR_AttachmentSummary_Details_6, ECIR.ECIR_AttachmentSummary_PIC_6, ECIR.ECIR_AttachmentSummary_ECD_6, ECIR.ECIR_AttachmentSummary_Details_7, ECIR.ECIR_AttachmentSummary_PIC_7, ECIR.ECIR_AttachmentSummary_ECD_7, ECIR.ECIR_AttachmentSummary_Details_8, ECIR.ECIR_AttachmentSummary_PIC_8, ECIR.ECIR_AttachmentSummary_ECD_8, ECIR.ECIR_AttachmentSummary_Details_9, ECIR.ECIR_AttachmentSummary_PIC_9, ECIR.ECIR_AttachmentSummary_ECD_9, ECIR.ECIR_AttachmentSummary_Details_10, ECIR.ECIR_AttachmentSummary_PIC_10, ECIR.ECIR_AttachmentSummary_ECD_10, ECIR.ECIR_Approval_DHName_7, ECIR.ECIR_Approval_DHApproval_7, ECIR.ECIR_Approval_DHName2_7, ECIR.ECIR_Approval_DHApproval2_7, CONVERT (VARCHAR(10), ECIR.ECIR_Approval_DHDate_7, 103) AS ECIR_Approval_DHDate_7, CONVERT (VARCHAR(10), ECIR.ECIR_Approval_DHDate2_7, 103) AS ECIR_Approval_DHDate2_7       "
            sqltext = sqltext & " FROM UserProfile INNER JOIN ECIR ON UserProfile.employee_no = ECIR.ECIR_ReqEmpNo"
            sqltext = sqltext & "  WHERE ECIR.ECIR_No = '" & ECIR_No & "'"
    
            Dim dsCustomers As DataSet_ECIR = GetData(sqltext)
    
            rds.Value = dsCustomers.Tables(0)
    
            report.DataSources.Add(rds)
    
    
            Dim mybytes As [Byte]() = report.Render("PDF")
            'Byte[] mybytes = report.Render("PDF"); for exporting to PDF
            Using fs As FileStream = File.Create("\\FUJIWEB\wwwroot\ECRSBRTEST2\ECIRAttachment\" & ECIR_No & ".pdf")
                fs.Write(mybytes, 0, mybytes.Length)
            End Using

    Private Function GetData(query As String) As DataSet_ECIR
    
            Dim connectionString As String = ConfigurationManager.ConnectionStrings("OESConnectionString").ConnectionString
    
            Dim cmd As New SqlCommand(query)
    
            Using con As New SqlConnection(connectionString)
    
                Using sda As New SqlDataAdapter()
    
                    cmd.Connection = con
    
                    sda.SelectCommand = cmd
    
                    Using dsCustomers As New DataSet_ECIR()
    
                        sda.Fill(dsCustomers, "ECIR")
    
                        Return dsCustomers
    
                    End Using
    
                End Using
    
            End Using
    
        End Function

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 28, 2015 11:32 PM