Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net SQl RS 2005-输入用户参数后自动导出为pdf_Vb.net_Reporting Services_Pdf Generation_Reportingservices 2005 - Fatal编程技术网

Vb.net SQl RS 2005-输入用户参数后自动导出为pdf

Vb.net SQl RS 2005-输入用户参数后自动导出为pdf,vb.net,reporting-services,pdf-generation,reportingservices-2005,Vb.net,Reporting Services,Pdf Generation,Reportingservices 2005,我有一个报告,要求用户输入他们的票证号,然后他们单击查看,它生成。相当标准。我想做的是,当他们单击“查看”时,报告自动导出为pdf。有人知道这是否可能,我将如何处理这件事吗 谢谢你的意见 我在ASP.NET上做过这个,但在VB.NET上没有。它涉及的是在后台向报表服务器发出请求,您可以在其中指定报表的呈现类型(在本例中为PDF),我的后台代码将下载该文件并将其保存到web服务器,然后将其作为PDF文件服务器备份给用户。用户只需填写参数并点击提交按钮 我可以想象,在需要提供文件之前,您可以执行与我

我有一个报告,要求用户输入他们的票证号,然后他们单击查看,它生成。相当标准。我想做的是,当他们单击“查看”时,报告自动导出为pdf。有人知道这是否可能,我将如何处理这件事吗


谢谢你的意见

我在ASP.NET上做过这个,但在VB.NET上没有。它涉及的是在后台向报表服务器发出请求,您可以在其中指定报表的呈现类型(在本例中为PDF),我的后台代码将下载该文件并将其保存到web服务器,然后将其作为PDF文件服务器备份给用户。用户只需填写参数并点击提交按钮

我可以想象,在需要提供文件之前,您可以执行与我一直遵循的步骤几乎相同的步骤,在表单环境中,您不需要向他们提供下载提示,因为它已经在计算机上,您所要做的就是打开文件(应该加载到默认的PDF查看器中)

更新:以下是一些代码,其中大部分是根据CodeProject教程编写的,但我记不起如何使用。进行了一些小的修改:

Public Sub ServeReport(ByVal URL As String, _
    ByVal Directory As String, ByVal Filename As String)

    Dim f As New FileIOPermission(PermissionState.None)
    Dim fs As FileStream

    If Not System.IO.Directory.Exists(Directory) Then
        System.IO.Directory.CreateDirectory(Directory)
    End If

    DownloadWebFile(URL, Directory & Filename)    

    fs = File.Open(Directory & Filename, FileMode.Open)

    Dim bytBytes(fs.Length) As Byte
    fs.Read(bytBytes, 0, fs.Length)
    fs.Close()

    Response.AddHeader("Content-disposition", _
               "attachment; filename=" & Filename)
    Response.ContentType = "application/octet-stream"
    Response.BinaryWrite(bytBytes)

    f.AllLocalFiles = FileIOPermissionAccess.AllAccess
    File.Delete(Directory & Filename)
End Sub
下面是DownloadWebFile子文件,它将实际发出报表服务器请求并下载文件并将其保存到本地磁盘

Public Shared Sub DownloadWebFile(ByVal URL As String, _
    ByVal DestFilename As String)

    'Create a web request to attach to the remote file 
    Dim WebFile As System.Net.WebRequest

    'Create a file stream for writing the file to the local filename 
    Dim LocalFile As System.IO.FileStream

    'Create some working variables for the copy process 
    Dim Buffer(16384) As Byte
    Dim BytesRead As Long

    'Open a WebRequest stream to the source file 
    WebFile = System.Net.WebRequest.Create(URL)

    'Credentials are required, pass the defaults 
    WebFile.Credentials = System.Net.CredentialCache.DefaultCredentials

    'Create the local file 
    LocalFile = New IO.FileStream(DestFilename, IO.FileMode.Create)

    'Download the file in 16k chunks 
    With WebFile.GetResponse.GetResponseStream
        Do
            BytesRead = .Read(Buffer, 0, 16384)
            LocalFile.Write(Buffer, 0, BytesRead)
        Loop Until BytesRead = 0
        .Close()
    End With

    WebFile = Nothing

    'Force all data out of memory and into the file before closing 
    LocalFile.Flush()
    LocalFile.Close()
    LocalFile = Nothing
End Sub
最后,下面是一个用法示例:

Dim URL As String
URL = reporturl & "&rs%3aCommand=Render&rs%3AFormat=PDF"

ServeReport(URL, "C:\Temp\", "MyReport.PDF")

我在ASP.NET上做过这个,但在VB.NET上没有。它涉及的是在后台向报表服务器发出请求,您可以在其中指定报表的呈现类型(在本例中为PDF),我的后台代码将下载该文件并将其保存到web服务器,然后将其作为PDF文件服务器备份给用户。用户只需填写参数并点击提交按钮

我可以想象,在需要提供文件之前,您可以执行与我一直遵循的步骤几乎相同的步骤,在表单环境中,您不需要向他们提供下载提示,因为它已经在计算机上,您所要做的就是打开文件(应该加载到默认的PDF查看器中)

更新:以下是一些代码,其中大部分是根据CodeProject教程编写的,但我记不起如何使用。进行了一些小的修改:

Public Sub ServeReport(ByVal URL As String, _
    ByVal Directory As String, ByVal Filename As String)

    Dim f As New FileIOPermission(PermissionState.None)
    Dim fs As FileStream

    If Not System.IO.Directory.Exists(Directory) Then
        System.IO.Directory.CreateDirectory(Directory)
    End If

    DownloadWebFile(URL, Directory & Filename)    

    fs = File.Open(Directory & Filename, FileMode.Open)

    Dim bytBytes(fs.Length) As Byte
    fs.Read(bytBytes, 0, fs.Length)
    fs.Close()

    Response.AddHeader("Content-disposition", _
               "attachment; filename=" & Filename)
    Response.ContentType = "application/octet-stream"
    Response.BinaryWrite(bytBytes)

    f.AllLocalFiles = FileIOPermissionAccess.AllAccess
    File.Delete(Directory & Filename)
End Sub
下面是DownloadWebFile子文件,它将实际发出报表服务器请求并下载文件并将其保存到本地磁盘

Public Shared Sub DownloadWebFile(ByVal URL As String, _
    ByVal DestFilename As String)

    'Create a web request to attach to the remote file 
    Dim WebFile As System.Net.WebRequest

    'Create a file stream for writing the file to the local filename 
    Dim LocalFile As System.IO.FileStream

    'Create some working variables for the copy process 
    Dim Buffer(16384) As Byte
    Dim BytesRead As Long

    'Open a WebRequest stream to the source file 
    WebFile = System.Net.WebRequest.Create(URL)

    'Credentials are required, pass the defaults 
    WebFile.Credentials = System.Net.CredentialCache.DefaultCredentials

    'Create the local file 
    LocalFile = New IO.FileStream(DestFilename, IO.FileMode.Create)

    'Download the file in 16k chunks 
    With WebFile.GetResponse.GetResponseStream
        Do
            BytesRead = .Read(Buffer, 0, 16384)
            LocalFile.Write(Buffer, 0, BytesRead)
        Loop Until BytesRead = 0
        .Close()
    End With

    WebFile = Nothing

    'Force all data out of memory and into the file before closing 
    LocalFile.Flush()
    LocalFile.Close()
    LocalFile = Nothing
End Sub
最后,下面是一个用法示例:

Dim URL As String
URL = reporturl & "&rs%3aCommand=Render&rs%3AFormat=PDF"

ServeReport(URL, "C:\Temp\", "MyReport.PDF")

我讨厌它不能正确识别VB.NET注释我讨厌它不能正确识别VB.NET注释