Friday, January 31, 2014

How to write SSRS report into server folder as Excel File

Public Sub RenderReportToExcel(ByVal _ReportPath As String)

    ReportViewerCostReport.Visible = True
    ReportViewerCostReport.Reset()
    ReportViewerCostReport.ServerReport.ReportPath = "/myReportFolder/reports/" + _ReportPath
    ReportViewerCostReport.ServerReport.ReportServerUrl = New System.Uri("http://localhost/ReportServer")
    ReportViewerCostReport.ServerReport.ReportServerCredentials = New MyReportServerCredentials2()

    Dim myparamProjectID As ReportParameter
    Dim myparamsProjectID As New List(Of ReportParameter)
    myparamProjectID = New ReportParameter("ProjectID", DropDownListPrj.SelectedValue)
    myparamsProjectID.Add(myparamProjectID)
    ReportViewerCostReport.ServerReport.SetParameters(myparamsProjectID)

    Dim warnings As Warning
    Dim streamIds As String
    Dim mimeType As String = String.Empty
    Dim encoding As String = String.Empty
    Dim extension As String = "xls"

    Dim bytes As Byte() = ReportViewerCostReport.ServerReport.Render("Excel", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

    Dim oFileStream As System.IO.FileStream
    Dim strFilePath As String = String.Empty
    strFilePath = Server.MapPath("~/YourFolderOnRoot/FileName.xls")

    oFileStream = New System.IO.FileStream(strFilePath, System.IO.FileMode.Create)
    oFileStream.Write(bytes, 0, bytes.Length)
    oFileStream.Close()

  End Sub
Reference url:http://forums.asp.net/t/1746293.aspx?How+to+write+SSRS+report+into+server+folder+as+Excel+File

No comments:

Post a Comment