Showing posts with label directly. Show all posts
Showing posts with label directly. Show all posts

Monday, February 20, 2012

rendering to browser instead to file

Did anyone have rendered a report in excel format directly to browser
instead to a file? I tried this code below wich works fine for pdf
rendering:
result = rs.Render("/MyReports/SVREL00104", "Excel", Nothing, _
Nothing, params, Nothing, _
Nothing, encoding, mime, history, warnings, streamsId)
Page.Response.ClearContent()
Page.Response.ClearHeaders()
Page.Response.ContentType = mime
Page.Response.BinaryWrite(result)
Page.Response.Flush()
Page.Response.Close()
This code should load the excel into the web browser window, but I'm getting
this errors:
1. A message box saying: The Microsoft Excel can not access the file:
'http://localhost/MyReports/test.aspx'.
2. An input box asking for an alternate name for 'Titulos_de_Impressao'
(Print Title) because this is already an internal name.
Any ideas?
[]s
Renato
--
----
Renato Aloi
Analista Programador
J&W Informática Ltda.
+55 11 30406675If you can tolerate a dialog box asking if the user wants to open or save,
this will work:
Response.ClearContent();
Response.ClearHeaders();
Response.AppendHeader("Content-Disposition",
"attachment;filename=\"MyReport.xls\"");
Response.BinaryWrite(result);
Response.End();
It works for PDF as well. There may be other ways, but this worked for us
so we stuck with it.
"Renato Aloi" wrote:
> Did anyone have rendered a report in excel format directly to browser
> instead to a file? I tried this code below wich works fine for pdf
> rendering:
> result = rs.Render("/MyReports/SVREL00104", "Excel", Nothing, _
> Nothing, params, Nothing, _
> Nothing, encoding, mime, history, warnings, streamsId)
> Page.Response.ClearContent()
> Page.Response.ClearHeaders()
> Page.Response.ContentType = mime
> Page.Response.BinaryWrite(result)
> Page.Response.Flush()
> Page.Response.Close()
> This code should load the excel into the web browser window, but I'm getting
> this errors:
> 1. A message box saying: The Microsoft Excel can not access the file:
> 'http://localhost/MyReports/test.aspx'.
> 2. An input box asking for an alternate name for 'Titulos_de_Impressao'
> (Print Title) because this is already an internal name.
> Any ideas?
> []s
> Renato
> --
> ----
> Renato Aloi
> Analista Programador
> J&W Informática Ltda.
> +55 11 30406675
>
>|||Thanks for your idea, Debra. Though I was really trying to avoid these
dialog boxes. In fact I am 'translating' all my systems' reports from
Crystal Reports to Reporting Services. The problem is my clients are already
using my systems with this export option to excel, without needing to save
any file. If I barelly whisper that they will need to take more clicks to do
something that is already working well, I will be exterminated.
However, I think the approach i will adopt is save a file to disk then use
this code:
Page.Response.ClearContent()
Page.Response.ClearHeaders()
Page.Response.ContentType = mime
Page.Response.WriteFile(savedFile)
Page.Response.Flush()
Page.Response.Close()
This approach works fine without any dialog boxes. The problem is at my
clients using web farms with load balance. I am afraid of exceptions, like
file not found.
Any other ideas, let me know, please.
[]s
Renato
"debra doty" <debradoty@.discussions.microsoft.com> escreveu na mensagem
news:22D7671D-13F2-413F-84B8-022E222F3A4C@.microsoft.com...
> If you can tolerate a dialog box asking if the user wants to open or save,
> this will work:
> Response.ClearContent();
> Response.ClearHeaders();
> Response.AppendHeader("Content-Disposition",
> "attachment;filename=\"MyReport.xls\"");
> Response.BinaryWrite(result);
> Response.End();
> It works for PDF as well. There may be other ways, but this worked for us
> so we stuck with it.
>
> "Renato Aloi" wrote:
> > Did anyone have rendered a report in excel format directly to browser
> > instead to a file? I tried this code below wich works fine for pdf
> > rendering:
> >
> > result = rs.Render("/MyReports/SVREL00104", "Excel", Nothing, _
> > Nothing, params, Nothing, _
> > Nothing, encoding, mime, history, warnings, streamsId)
> >
> > Page.Response.ClearContent()
> > Page.Response.ClearHeaders()
> > Page.Response.ContentType = mime
> > Page.Response.BinaryWrite(result)
> > Page.Response.Flush()
> > Page.Response.Close()
> >
> > This code should load the excel into the web browser window, but I'm
getting
> > this errors:
> >
> > 1. A message box saying: The Microsoft Excel can not access the file:
> > 'http://localhost/MyReports/test.aspx'.
> >
> > 2. An input box asking for an alternate name for 'Titulos_de_Impressao'
> > (Print Title) because this is already an internal name.
> >
> > Any ideas?
> >
> > []s
> > Renato
> >
> > --
> > ----
> > Renato Aloi
> > Analista Programador
> > J&W Informática Ltda.
> > +55 11 30406675
> >
> >
> >

Rendering the ASP.NET local report directly to PDF

Hi,

Since it is not possible to print from a local report in ASP.Net is there anyway to directly render to a PDF or hide the Local report rendering and automatically goto the PDF either in the web page or as a popup.

Thanks

Hi,

You can try this code:

string path = @."D:/Folder/MyFile.pdf";
WebClient client = new
WebClient();
Byte[] buffer = client.DownloadData(path);

if (buffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length",buffer.Length.ToString());
Response.BinaryWrite(buffer);
}

Hope this helps,

Vivek

|||

Can this be done on a report on a server and a parameter is passed?

For example, when a button is clicked in a page, then it will pass a parameter to SSRS and then, in turn, returns a PDF file. (So there's no need for a report viewer)

I am not sure if its possible. Please advise. Thanks!

Lloyd

|||

Lloyd,

How are you returning the PDF file? SSRS will return only data (I do not have much experience in SSRS), I have worked on Crystal Reports and it exported idrectly to PDF.

If you have data then you can format and show it to PDF. You can change the Response.ContentType as I mentioned before or use some tools like:

http://www.websupergoo.com/abcpdf-1.htm

Hope this helps,

Vivek

|||

Hi!

Thanks for the reply!

I'm thinking if this can be done. When I click the "Print" button, the report will be generated (PDF), and the standard pop up message of browser would come up, asking if the user would want to open or save the generated file.

Lloyd

|||

Lloyd,

You can first call the SSRS on the Print button click and then bind the resulting data to some data bound control, such as a DataGrid or GridView. After the bind, you can change the Response.ContentType property to "pdf". See my blog entry for details:

http://geekswithblogs.com/vivek

You can also try an Open Source PDF Report Server Control:http://sourceforge.net/projects/npdf/

Hope this helps,

Vivek

|||

Try this:

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

Dim rs As New msfirm_db_stl.ReportingService
'rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim myCred As New NetworkCredential("Username", "Password", "Domain")
rs.Credentials = myCred

' Render arguments
Dim result As Byte() = Nothing
Dim reportPath As String = "/ImportedReports/" & Me.ReportName
Dim format As String = Me.ReportFormat
Dim historyID As String = Nothing
Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

' Prepare report parameter.
Dim params() As String
params = Me.Parameters.Split("&")
Dim nParams As Integer = 0
Dim parameters() As msfirm_db_stl.ParameterValue
If params.Length > 0 And Me.Parameters <> String.Empty Then
ReDim parameters(IIf(params.Length > 0, params.Length - 1, 0))
For Each s As String In params
If s <> String.Empty Then
Dim keyval() As String = s.Split("=")
parameters(nParams) = New msfirm_db_stl.ParameterValue
parameters(nParams).Name = keyval(0)
parameters(nParams).Value = keyval(1)
nParams += 1
End If
Next
End If

Dim testparms() As msfirm_db_stl.ReportParameter = rs.GetReportParameters(reportPath, historyID, False, Nothing, Nothing)
If (testparms.Length.ToString) <> (nParams.ToString) Then
Response.Redirect(ConfigurationSettings.AppSettings.Get("ReportServerURL") & "?%2fImportedReports%2f" & Me.ReportName & "&rs%3aCommand=Render&rs%3aFormat=HTML4.0&rc%3aToolbar=True&rc%3aJavaScript=True")
End If

'Set Web Service user credentials
Dim credentials As msfirm_db_stl.DataSourceCredentials() = Nothing
Dim showHideToggle As String = Nothing
Dim encoding As String
Dim mimeType As String
Dim warnings As msfirm_db_stl.Warning() = Nothing
Dim reportHistoryParameters As msfirm_db_stl.ParameterValue() = Nothing
Dim streamIDs As String() = Nothing
Dim sh As New msfirm_db_stl.SessionHeader
rs.SessionHeaderValue = sh

Try
result = rs.Render(reportPath, format, historyID, devInfo, parameters, credentials, showHideToggle, encoding, mimeType, reportHistoryParameters, warnings, streamIDs)
sh.SessionId = rs.SessionHeaderValue.SessionId
Catch ex As SoapException

End Try
'' Write the contents of the report to an MHTML file.
Try
Response.Buffer = True
Select Case Me.ReportFormat
Case "EXCEL"
Response.ContentType = "application/vnd.ms-excel"
Case "HTML4.0", "HTMLOWC"
Response.ContentType = "text/html"
Case "PDF"
Response.ContentType = "Application/PDF"
End Select

'Response.AddHeader("Content-Disposition", "attachment;filename=" & Me.ReportName & ".pdf")
Response.BinaryWrite(result)
Catch ex As Exception

End Try
End Sub

Rendering Report directly in the MS Excel

Hi,
We have multiple reports created in the SRS 2005. What is the best approach
to directly exporting (rendering) the created reports in Excel without using
any report viewer control or report manager for exporting on click of the
button.
Thanx in advance.You can call the report using the url access, as:
http://<server>/ReportServer?/<report
path>&rs:Command=Render&rs:Format=EXCEL
Jeronimo Vogt
"Parimal" <Parimal@.discussions.microsoft.com> wrote in message
news:3761A0CF-EFA4-4266-8E15-4832D6AF3814@.microsoft.com...
> Hi,
> We have multiple reports created in the SRS 2005. What is the best
approach
> to directly exporting (rendering) the created reports in Excel without
using
> any report viewer control or report manager for exporting on click of the
> button.
> Thanx in advance.|||The new MS Reports tool (an addition to Excel 2003) is worth looking at - it
might meet your requirements. I think it is supposed to be released sometime
in Dec 2005 - anyone has any confirmed information on the release date?
For details on MS Reports:
http://download.microsoft.com/download/d/6/f/d6f66e9b-1b72-4192-b4ae-cecbad1a4903/MSReportsTCS.doc
-K
"Jeronimo Vogt" wrote:
> You can call the report using the url access, as:
> http://<server>/ReportServer?/<report
> path>&rs:Command=Render&rs:Format=EXCEL
> Jeronimo Vogt
> "Parimal" <Parimal@.discussions.microsoft.com> wrote in message
> news:3761A0CF-EFA4-4266-8E15-4832D6AF3814@.microsoft.com...
> > Hi,
> > We have multiple reports created in the SRS 2005. What is the best
> approach
> > to directly exporting (rendering) the created reports in Excel without
> using
> > any report viewer control or report manager for exporting on click of the
> > button.
> > Thanx in advance.
>
>