Friday, March 9, 2012

OOpening report in new page without using url.

Sounds simple but here is what I need. I have an aspx webform that asks the user for 19 parameters that my report requires. I need to validate the form and have a button that the user can click and have the report open in a new window. Like I said the report has 19 parameters and we would like to avoid passing the parameters in the url. Here is what I’ve tried:

Using cross-page postback I can pass the parameters captured in the Getparameters webform to the viewreport webpage but it opens on the same window. I can use a regular button or a linkbutton and added “onclick” attributes to run clientside validation before submitting a form. The viewreport webpage has a reportviewer control. I just need to open the report in a new window.

Tried javascript window.open in several places (btnView “onclick”, linkbutton “onclick”, registerclientscriptblock (runs after the form is posted) all giving me the error “object null reference exception” on the report parameters.

Lastly I’m trying to use SOAP and running render method for button on_click but I keep getting the error report path not valid report path needs to be less than 260 characters and must start with slash. Here is the code that I’m using for render method:

Dim rsAsNew RSWebReference.ReportingService

rs.Credentials = System.Net.CredentialCache.DefaultCredentials

'Render Arguments

Dim resultAsByte =Nothing

Dim reportPathAsString ="/Sales/MonthlySales"

Dim formatAsString ="PDF"

Dim historyIDAsString =Nothing

Dim devInfoAsString = “<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

'Prepare report Parameters

Dim parameters(0)As RSWebReference.ParameterValue

parameters(0) =New RSWebReference.ParameterValue

parameters(0).Name ="Date"

parameters(0).Value ="09/10/2006"

Dim credentials()As RSWebReference.DataSourceCredentials =Nothing

Dim showhidetoggleAsString =Nothing

Dim encodingAsString =""

Dim mimeTypeAsString =""

Dim warnings()As RSWebReference.Warning =Nothing

Dim reportHistoryParametersAs RSWebReference.ParameterValue() =Nothing

Dim streamIDAsString() =Nothing

rs.Render("MonthlySales","PDF", historyID, devInfo, parameters, credentials, showhidetoggle, encoding, mimeType, reportHistoryParameters, warnings, streamID)

I just want to know if what I want to accomplish is even posible because I’ve been at this for over a week, going Crazy!

I thought maybe the report needed credentials set instead of nothing, but don’t know how to do that. Using VS 2005, SQL 2005

Any help is immensely appreciated!

I've tried a bunch of different things myself and can't seem to get it. It would be nice that after you call rs.Render(), rs would have a property set to the url of what you just ran. There is a method rs.GetReportLink(ReportName as String) but it just returns the url to the report with none of the query string. My guess is you'll be writing a URL Generator and using a RegisterStartUp script to call a javascript:window.open(). Works well for me.|||

I finally figured it out. Seems that I had the incorrect webreference and was sending the wrong parameters, but here is my solution.

I added a web reference to ReportExecution2005 and used the following code:

Response.BufferOutput = True

Response.ClearContent()

Response.ClearHeaders()

Response.AddHeader("content-type", ContentType)

Response.AddHeader("Content-Length", result.Length.ToString)

Response.AddHeader("content-disposition", "attachement;filename='" & FileName & "'")

Response.BinaryWrite(result)

Response.Flush()

Response.Clear()

'End the response

Response.End()

By using content-disposition "attachement" I have the browser ask the user to open or save the report. To have this open in a new window I had to go with the form target=_blank. I did find that different MIME types yield different results. For example using "application/pdf" will open the pdf document in a the recently opened new browser window. Using "application/x-pdf" will open the pdf document in acrobat session leaving a blank page behind. I also tried exporting the report to excel, but the onlyl issue with excel is that it renders the report formated so some columns do not match the cells. I haven't figured out how to render that correctly.

No comments:

Post a Comment