I am trying to find the best way (as well as sample code) to render a report
(probably in PDf format) to a shared directory when the user clicks on a
button called from a web page. The report should be converted to PDF and
placed in a predefined location without any interaction from the user ,
except the click of course. Any ideas, sites, sample code?here is some sample code (using VS.net 2005 against RS 2000)
to make the web reference, right click on 'references' and 'add web reference'
then enter
http://<servername>/reportserver/reportservice.asmx
and name/rename it 'reportservice' to match with my sample
this is just in a win32 vb.net form with a button to run the code
Private Sub ReportGen(ByVal OutputFormat As String, ByVal ReportLocation As
String, ByVal startdt As String, ByVal enddt As String, ByVal CustRepGp As
Integer, ByVal CustName As String)
Dim rs As New ReportService.ReportingService()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
' Render arguments
Dim result As Byte() = Nothing
Dim reportPath As String = ReportLocation
Dim format As String = OutputFormat
Dim historyID As String = Nothing
Dim devInfo As String ="<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"
' Prepare report parameter.
'this report takes 3 parameters - if you don't use any then scrap this bit
'N.B. the parameter names are case sensitive as per what you called them in
the
'report designer (you can also check using report
manger-properties-parameters)
Dim parameters(2) As ReportService.ParameterValue
parameters(0) = New ParameterValue()
parameters(0).Name = "startDate"
parameters(0).Value = startdt.ToString()
parameters(1) = New ParameterValue()
parameters(1).Name = "endDate"
parameters(1).Value = enddt.ToString()
parameters(2) = New ParameterValue()
parameters(2).Name = "OpsCustGroupID"
parameters(2).Value = CustRepGp.ToString()
Dim credentials As DataSourceCredentials() = Nothing
Dim showHideToggle As String = Nothing
Dim encoding As String
Dim mimeType As String
Dim warnings As Warning() = Nothing
Dim reportHistoryParameters As ParameterValue() = Nothing
Dim streamIDs As String() = Nothing
Dim sh As New SessionHeader()
rs.SessionHeaderValue = sh
Try
'this is the important bit, this is calling the RENDER method on the report
web service
result = rs.Render(reportPath, format, historyID, devInfo,
parameters, credentials, showHideToggle, encoding, mimeType,
reportHistoryParameters, warnings, streamIDs)
sh.SessionId = rs.SessionHeaderValue.SessionId
Console.WriteLine("SessionID after call to Render: {0}",
rs.SessionHeaderValue.SessionId)
Console.WriteLine("Execution date and time: {0}",
rs.SessionHeaderValue.ExecutionDateTime)
Console.WriteLine("Is new execution: {0}",
rs.SessionHeaderValue.IsNewExecution)
Catch err As Exception
Console.WriteLine(err.Message)
End Try
' Write the contents of the report to an MHTML file.
Try
'need to change EXCEL to XLS otherwise the app won't recognise it
Dim fileout As String = CustName & "_" & startdt & "_" & enddt &
"." & IIf(OutputFormat = "EXCEL", "XLS", OutputFormat)
Dim stream As FileStream = File.Create("YOUR_FOLDER\" & fileout,
result.Length)
Console.WriteLine("File created: " & fileout)
stream.Write(result, 0, result.Length)
Console.WriteLine("Result written to the file.")
stream.Close()
Catch err As Exception
Console.WriteLine(err.Message)
End Try
End Sub
'in order to call the above code you will need something like
ReportGen("YOUR FORMAT e.g. PDF",
"/folderonReportServer/anotherfolder/REPORTNAME", "MY PARAM 0", "MY PARAM 1",
ANOTHERPARAM, AnotherParamforNamingTheFileOnly)
obviously you can export to other formats
N.B. all non HTML formats come back in a single stream so you can use this
example, can't remember how you do it in HTML but it's pretty similar
"Bon733" wrote:
> I am trying to find the best way (as well as sample code) to render a report
> (probably in PDf format) to a shared directory when the user clicks on a
> button called from a web page. The report should be converted to PDF and
> placed in a predefined location without any interaction from the user ,
> except the click of course. Any ideas, sites, sample code?|||Hey Adolf,
I am quite new to this kind of thing, but this is exactly what I'm trying
to do (autorender to pdf). I am having a couple of difficulties however
trying to understand it all. I have a couple basic questions (I think).
I've created a simple 1 form vb.net application with a button that says
"Create PDF".
For simplicity I've hard coded my 1 parameter (the Invoice Number "Id")
I've modified your code to the point where VB has no errors but Im missing
some values for variables.
1. ReportLocation: How do I determine this? Is this a network location
where the .rdl exists, or is this the ReportServer URL that I see if I access
the report through ReportManager, or is it something else...? Also, should
this include .rdl extension
2. Where does the PDF get created? I'm not sure I understand where the
output goes, as I'm not providing it with a "dump" location
Any help you can give me is greatly appreciated ...
Michael C
"adolf garlic" wrote:
> here is some sample code (using VS.net 2005 against RS 2000)
> to make the web reference, right click on 'references' and 'add web reference'
> then enter
> http://<servername>/reportserver/reportservice.asmx
> and name/rename it 'reportservice' to match with my sample
> this is just in a win32 vb.net form with a button to run the code
> Private Sub ReportGen(ByVal OutputFormat As String, ByVal ReportLocation As
> String, ByVal startdt As String, ByVal enddt As String, ByVal CustRepGp As
> Integer, ByVal CustName As String)
> Dim rs As New ReportService.ReportingService()
> rs.Credentials = System.Net.CredentialCache.DefaultCredentials
> ' Render arguments
> Dim result As Byte() = Nothing
> Dim reportPath As String = ReportLocation
> Dim format As String = OutputFormat
> Dim historyID As String = Nothing
> Dim devInfo As String => "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"
> ' Prepare report parameter.
> 'this report takes 3 parameters - if you don't use any then scrap this bit
> 'N.B. the parameter names are case sensitive as per what you called them in
> the
> 'report designer (you can also check using report
> manger-properties-parameters)
> Dim parameters(2) As ReportService.ParameterValue
> parameters(0) = New ParameterValue()
> parameters(0).Name = "startDate"
> parameters(0).Value = startdt.ToString()
> parameters(1) = New ParameterValue()
> parameters(1).Name = "endDate"
> parameters(1).Value = enddt.ToString()
> parameters(2) = New ParameterValue()
> parameters(2).Name = "OpsCustGroupID"
> parameters(2).Value = CustRepGp.ToString()
> Dim credentials As DataSourceCredentials() = Nothing
> Dim showHideToggle As String = Nothing
> Dim encoding As String
> Dim mimeType As String
> Dim warnings As Warning() = Nothing
> Dim reportHistoryParameters As ParameterValue() = Nothing
> Dim streamIDs As String() = Nothing
> Dim sh As New SessionHeader()
> rs.SessionHeaderValue = sh
> Try
> 'this is the important bit, this is calling the RENDER method on the report
> web service
> result = rs.Render(reportPath, format, historyID, devInfo,
> parameters, credentials, showHideToggle, encoding, mimeType,
> reportHistoryParameters, warnings, streamIDs)
> sh.SessionId = rs.SessionHeaderValue.SessionId
> Console.WriteLine("SessionID after call to Render: {0}",
> rs.SessionHeaderValue.SessionId)
> Console.WriteLine("Execution date and time: {0}",
> rs.SessionHeaderValue.ExecutionDateTime)
> Console.WriteLine("Is new execution: {0}",
> rs.SessionHeaderValue.IsNewExecution)
> Catch err As Exception
> Console.WriteLine(err.Message)
> End Try
> ' Write the contents of the report to an MHTML file.
> Try
> 'need to change EXCEL to XLS otherwise the app won't recognise it
> Dim fileout As String = CustName & "_" & startdt & "_" & enddt &
> "." & IIf(OutputFormat = "EXCEL", "XLS", OutputFormat)
> Dim stream As FileStream = File.Create("YOUR_FOLDER\" & fileout,
> result.Length)
> Console.WriteLine("File created: " & fileout)
> stream.Write(result, 0, result.Length)
> Console.WriteLine("Result written to the file.")
> stream.Close()
> Catch err As Exception
> Console.WriteLine(err.Message)
> End Try
> End Sub
> 'in order to call the above code you will need something like
> ReportGen("YOUR FORMAT e.g. PDF",
> "/folderonReportServer/anotherfolder/REPORTNAME", "MY PARAM 0", "MY PARAM 1",
> ANOTHERPARAM, AnotherParamforNamingTheFileOnly)
>
> obviously you can export to other formats
> N.B. all non HTML formats come back in a single stream so you can use this
> example, can't remember how you do it in HTML but it's pretty similar
>
> "Bon733" wrote:
> > I am trying to find the best way (as well as sample code) to render a report
> > (probably in PDf format) to a shared directory when the user clicks on a
> > button called from a web page. The report should be converted to PDF and
> > placed in a predefined location without any interaction from the user ,
> > except the click of course. Any ideas, sites, sample code?sql
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment