Hi,
Below is the code I have tried. I get an xls file with the right name in a dialog box to open, save or cancel. However, when I try to open it, I get the message that the Excel 97-2003 file is corrupted.
Appreciate if you could help me with appropriate modifications to the below code.
Thanks,
Swamy
Below is the code I have tried. I get an xls file with the right name in a dialog box to open, save or cancel. However, when I try to open it, I get the message that the Excel 97-2003 file is corrupted.
Appreciate if you could help me with appropriate modifications to the below code.
Thanks,
Swamy
Code:
Protected Overrides Sub GenerateReport()
Dim ReportFileName As String = "/ITG/BatteryReporting/"
Dim Params As New StringBuilder
Try
If ReportTypeRB1.Checked Then
ReportFileName = String.Format("{0}TrendBaseValueTabular", ReportFileName)
ElseIf ReportTypeRB2.Checked Then
ReportFileName = String.Format("{0}TrendBaseValueGraphDataPoints", ReportFileName)
End If
Dim YellowValueText As String = ""
Dim RedValueText As String = ""
Dim BaseValueText As String = ""
If Me.ReportTypeRB1.Checked Then
YellowValueText = Me.YellowTB.Text
RedValueText = Me.RedTB.Text
BaseValueText = Me.BaseTB.Text
End If
Params.Append(Me.GetReport_P_Param())
Params.Append(Me.GetReport_R_Param(MyMaster.TreeViewEntityTableHierarchyForSelectedPage))
Params.Append(Me.GetReport_T_Param(Me.ColumnToTrendDD))Params.Append(Me.GetReport_V_Param(YellowValueText, MyAppConstants.ReportWarningColor, _
RedValueText, MyAppConstants.ReportAlertColor, BaseValueText))
Params.Append(Me.GetReport_I_Params(True, (Not Me.ReportTypeRB1.Checked), "", "", ""))
Dim URL As String = String.Format("{0}?{1}&{2}&rs:Format=Excel&rs:Command=Render&rc:Parameters=false", _
MyAppSettings.SSRSServerURL, ReportFileName, Params.ToString)
Dim MyRequest As HttpWebRequest = CType(WebRequest.Create(URL), HttpWebRequest)
MyRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim HttpResponse As HttpWebResponse = CType(MyRequest.GetResponse(), HttpWebResponse)Dim SR As BinaryReader = New BinaryReader(HttpResponse.GetResponseStream(), Encoding.Unicode)
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "application/octet-stream"
'Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment; filename=" & Chr(34) & Left(Me.PageName, (Me.PageName.Length - 5)) & ".xls" & Chr(34))
Dim Count As Integer = 1024
Dim Buffer(Count - 1) As Byte
Count = SR.Read(CType(Buffer, Byte()), 0, Count)
Do Until Count = 0
' modify each byte in buffer here
Response.BinaryWrite(Buffer)
Count = SR.Read(Buffer, 0, Count)
Loop
Response.Flush()
Response.Close()
Catch ex As Exception
Throw New ApplicationException("Trending Report not found.")
End Try
End Sub
Comment