通过程序的方式将Reporting Service 报表转成 PDF--- SQL Server Reporting Services 2005

通过程序的方式将Reporting Service 报表转成 PDF,搞了好久,终于搞定了,记录下

 

1.创建报表并发布

2.建立项目,并在项目中加入 web 引用

http://localhost/ReportServer  取名为  ReportService2005/ReportService2005.asmx

http://localhost/ReportServer  取名为  ReportExecution2005/ReportExecution2005.asmx

3.代码如下

       Dim rs As ReportService2005.ReportingService2005
        Dim rsExec As ReportExecution2005.ReportExecutionService
        ' Create a new proxy to the web service
        rs = New ReportService2005.ReportingService2005()
        rsExec = New ReportExecution2005.ReportExecutionService()
        ' Authenticate to the Web service using Windows credentials
        rs.Credentials = System.Net.CredentialCache.DefaultCredentials
        rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials
        ' Assign the URL of the Web service
        rs.Url = "http://localhost/ReportServer/ReportService2005.asmx"
        rsExec.Url = "http://localhost/ReportServer/ReportExecution2005.asmx"
        ' Prepare Render arguments
        Dim historyID As String = Nothing
        Dim deviceInfo As String = Nothing
        Dim format As String = "PDF"
        Dim results As [Byte]()
        Dim encoding As String = [String].Empty
        Dim mimeType As String = [String].Empty
        Dim extension As String = [String].Empty
        Dim warnings As ReportExecution2005.Warning() = Nothing
        Dim streamIDs As String() = Nothing
        ' Default Path;
        Dim fileName As String = "c:/samplereport.pdf"
        ' Define variables needed for GetParameters() method
        ' Get the report name
        Dim _reportName As String = "/AdventureWorks Sample Reports/Sales Order Detail"
        Dim _historyID As String = Nothing
        Dim _forRendering As Boolean = False
        Dim _values As ReportService2005.ParameterValue() = Nothing
        Dim _credentials As ReportService2005.DataSourceCredentials() = Nothing
        Dim _parameters As ReportService2005.ReportParameter() = Nothing
        Try
            ' Get if any parameters needed.
            _parameters = rs.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials)
            ' Load the selected report.
            Dim ei As ReportExecution2005.ExecutionInfo = rsExec.LoadReport(_reportName, historyID)
            ' Prepare report parameter.
            ' Set the parameters for the report needed.
            Dim parameters As ReportExecution2005.ParameterValue() = New ReportExecution2005.ParameterValue(0) {}
            ' Place to include the parameter.
            If _parameters.Length > 0 Then
                'parameters(0) = New ReportExecution2005.ParameterValue()
                'parameters(0).Label = "verzamelgroepAP"
                'parameters(0).Name = "verzamelgroepAP"
                'parameters(0).Value = "true"
                parameters(0) = New ReportExecution2005.ParameterValue()
                parameters(0).Label = "Sales Order Number"
                parameters(0).Name = "SalesOrderNumber"
                parameters(0).Value = "SO50750"
            End If
            rsExec.SetExecutionParameters(parameters, "en-us")
            results = rsExec.Render(format, deviceInfo, extension, encoding, mimeType, warnings, streamIDs)
            '' Create a file stream and write the report to it
            'Using stream As FileStream = File.OpenWrite(fileName)
            '    stream.Write(results, 0, results.Length)
            'End Using
            'Save to Client
            Response.ClearContent()
            Response.AddHeader("Content-Disposition", "attachment; filename=aaa.pdf")
            Response.ContentType = "application/pdf"
            Response.BinaryWrite(results)
            Response.Flush()
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try

 

参考:

http://www.codeproject.com/KB/reporting-services/PDFUsingSQLRepServices.aspx

http://geekswithblogs.net/bsherwin/archive/2007/04/29/112094.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值