473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Difficulty in exposing an SSRS excel report over the internet

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



Expand|Select|Wrap|Line Numbers
  1. Protected Overrides Sub GenerateReport() 
  2. Dim ReportFileName As String = "/ITG/BatteryReporting/"
  3.  
  4. Dim Params As New StringBuilder 
  5. Try
  6.  
  7. If ReportTypeRB1.Checked Then
  8.  
  9. ReportFileName = String.Format("{0}TrendBaseValueTabular", ReportFileName) 
  10. ElseIf ReportTypeRB2.Checked Then
  11.  
  12. ReportFileName = String.Format("{0}TrendBaseValueGraphDataPoints", ReportFileName) 
  13. End If
  14.  
  15. Dim YellowValueText As String = ""
  16.  
  17. Dim RedValueText As String = ""
  18.  
  19. Dim BaseValueText As String = ""
  20.  
  21. If Me.ReportTypeRB1.Checked Then
  22.  
  23. YellowValueText = Me.YellowTB.Text 
  24. RedValueText = Me.RedTB.Text
  25.  
  26. BaseValueText = Me.BaseTB.Text 
  27. End If
  28.  
  29. Params.Append(Me.GetReport_P_Param()) 
  30. Params.Append(Me.GetReport_R_Param(MyMaster.TreeViewEntityTableHierarchyForSelectedPage))
  31.  
  32. Params.Append(Me.GetReport_T_Param(Me.ColumnToTrendDD))Params.Append(Me.GetReport_V_Param(YellowValueText, MyAppConstants.ReportWarningColor, _ 
  33. RedValueText, MyAppConstants.ReportAlertColor, BaseValueText))
  34.  
  35. Params.Append(Me.GetReport_I_Params(True, (Not Me.ReportTypeRB1.Checked), "", "", ""))
  36.  
  37. Dim URL As String = String.Format("{0}?{1}&{2}&rs:Format=Excel&rs:Command=Render&rc:Parameters=false", _ 
  38. MyAppSettings.SSRSServerURL, ReportFileName, Params.ToString)
  39.  
  40.  
  41.  
  42. Dim MyRequest As HttpWebRequest = CType(WebRequest.Create(URL), HttpWebRequest) 
  43. MyRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
  44.  
  45. Dim HttpResponse As HttpWebResponse = CType(MyRequest.GetResponse(), HttpWebResponse)Dim SR As BinaryReader = New BinaryReader(HttpResponse.GetResponseStream(), Encoding.Unicode) 
  46. Response.ClearHeaders()
  47.  
  48. Response.ClearContent()
  49.  
  50. Response.ContentType = "application/octet-stream"
  51.  
  52. 'Response.ContentType = "application/vnd.ms-excel"
  53.  
  54. Response.AddHeader("content-disposition", "attachment; filename=" & Chr(34) & Left(Me.PageName, (Me.PageName.Length - 5)) & ".xls" & Chr(34)) 
  55. Dim Count As Integer = 1024
  56.  
  57. Dim Buffer(Count - 1) As Byte
  58.  
  59. Count = SR.Read(CType(Buffer, Byte()), 0, Count) 
  60. Do Until Count = 0
  61.  
  62. ' modify each byte in buffer here 
  63.  
  64. Response.BinaryWrite(Buffer)
  65.  
  66. Count = SR.Read(Buffer, 0, Count)
  67.  
  68. Loop
  69.  
  70. Response.Flush()
  71.  
  72. Response.Close()
  73.  
  74. Catch ex As Exception 
  75. Throw New ApplicationException("Trending Report not found.")
  76.  
  77. End Try
  78.  
  79. End Sub
Oct 16 '08 #1
1 1560
Frinavale
9,735 Expert Mod 8TB
In line 55 in your posted code...you are declaring:
Dim Count As Integer = 1024

How do you know that count is 1024?
What happens if this number should be bigger?

I think this is where your problem is.

Or maybe its when you are getting the file in the first place.

When you get the file, you can write it's stream directly into the Response if you want to.....

Here's a Very simple example of writing an image to the Response:
Expand|Select|Wrap|Line Numbers
  1.  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.  
  3.         Response.ContentType = "image/jpg"
  4.         Dim fs As FileStream = File.OpenRead(Server.MapPath("~/Images/DogObedienceTraining.jpg"))
  5.         Dim b(fs.Length) As Byte
  6.         For i = 0 To fs.Length - 1
  7.             b(i) = fs.ReadByte
  8.         Next
  9.         fs.Close()
  10.         Response.BinaryWrite(b)
  11.     End Sub
The above code is in the Page_Load event of an ASPX page. When called on, this ASPX page does not produce HTML as it normally would...it sends a picture instead. That's why the ContentType was changed to "image/jpg". The file is read off of the server and dumped directly into the the Response stream.

-Frinny
Oct 16 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Wes Groleau | last post by:
Is there a reasonably simple way to dump an SSRS report into Excel format automatically at a scheduled time without using Report Manager/Report Server? Creating the report was easy, but we seem...
5
by: Sport Girl | last post by:
Hi again my great online assistants, just would like to say that i'm testing the script under unix , and after researches on the internet, i have realised that to resolve 500 Internal Server Error,...
0
by: jobs | last post by:
Re: SSRS report viewer Execution ' ' cannot be found (rsExecutionNotFound) Reserved.ReportViewerWebControl.axd Every now and then, my users get this error while in the Reportviewer. Usually,...
0
by: Aswanth | last post by:
I'm Working with Asp.Net with C#.. & I'm Generating Reports in SSRS-2005.. Till Now I'm Generating Reports in SSRS-2005 with Stored Procedure.. in Which I'm Generating Reports for One...
5
by: Aswanth | last post by:
I'm Using Asp.Net with C# & Working with SSRS 2005 for Generating Reports.. The Following Expression I'm using in Reports to Show the Percentage of Particular Items in REPORT.. ...
1
by: Aswanth | last post by:
I'm Using Asp.Net with C# & SSRS 2005 for Generating Reports.. I'm Having HUGE Data in Microsoft Excel Sheets .. I want to Get this Data from this Microsoft Excel Sheets & to Generate REPORTS in...
8
by: Rich P | last post by:
(this is way easier in VB.Net -- but here is how to do it from Access) '------------------------------------------------ Public Declare Function apiShellExecute Lib "shell32.dll" _ Alias...
3
by: nandithadevaraj | last post by:
When exporting a report to excel, is it possible to keep the properties around numeric values? More specifically - when exporting a report into excel, all of the numbers in a currency column are...
0
by: napstar | last post by:
I have a multi value Country parameter in SSRS which is populated by an Oracle dataset.There is also a province parameter which is populated based on the Country selected by the user. These...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.