June 30, 2005 at 7:33 pm
Hey Guys,
I have been looking for some help with this. I can call reports using the code below that do not require parameters and it works perfectly. However, some reports DO need parameters (sometimes many) and I am unsure how to do this.
What changes do I need to make here so that I can pass paramaters (their names and values) to the function below. Have been trying very hard at this and have had some luck, but never got it working. I think I got close, but I am not sure if what I did was correct, so here is the original code I started with.
Hope someone can help...I'm desperate.
Friend Shared Sub RenderPDFReport(ByVal reportURL As String)
Dim result As Byte() = Nothing
Dim historyID As String = Nothing
Dim format As String = "PDF"
Dim devInfo As String = Nothing
Dim credentials As ReportServer.DataSourceCredentials() = Nothing
Dim showHideToggle As String = Nothing
Dim encoding As String
Dim mimeType As String
Dim warnings As ReportServer.Warning() = Nothing
Dim reportHistoryParameters As ReportServer.ParameterValue() = Nothing
Dim streamIDs As String() = Nothing
Dim proxyParameters() As ReportServer.ParameterValue = Nothing
Dim rs As ReportServer.ReportingService = New ReportServer.ReportingService
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Try
result = rs.Render(reportURL, format, historyID, devInfo, proxyParameters, credentials, showHideToggle, encoding, mimeType, reportHistoryParameters, warnings, streamIDs)
'Write the contents of the report to a pdf, and then open it
Dim filePath As String = System.IO.Path.GetTempFileName() & ".pdf"
Dim stream As System.IO.FileStream = System.IO.File.Create(filePath, result.Length)
stream.Write(result, 0, result.Length)
stream.Close()
'Show the report
Process.Start(filePath)
Catch ex As System.Net.WebException
MessageBox.Show("You do not have sufficient permissions or the report server could not be contacted. " & Environment.NewLine & "Please see your system administrator. (" & ex.Message & ")", "Could Not Access Report Server", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class
June 30, 2005 at 8:42 pm
Currently of all the parameters in our repotrs we only need to specifically set one per report. Most of the other parameters use system defaults like current date/time/user/etc... Hadn't really thought about that, but it seems a bit strange how that has worked out ![]()
We use this snippet of code to set the DefaultValue for the parameter we change. You might be able to hack around with this. I believe the trick is to set the ForRendering property to true so the parameter list is returned.
static void SetParms(ReportingService rs, string RptPath, string ParamValue)
{
// Report Parameters
bool forRendering = true;
string historyID = null;
ParameterValue[] values = null;
DataSourceCredentials[] credentials = null;
ReportParameter[] parameters = null;
parameters = rs.GetReportParameters(RptPath, historyID, forRendering, values, credentials);
if (parameters.Length > 0)
{
parameters[0].DefaultValues = new string[] {ParamValue};
rs.SetReportParameters(RptPath, parameters);
}
}
--------------------
Colt 45 - the original point and click interface ![]()
June 30, 2005 at 8:44 pm
Oops ... should note that this is C# code ![]()
--------------------
Colt 45 - the original point and click interface ![]()
June 30, 2005 at 8:50 pm
Thanks for your help. I don't know much of C# but I will probably be able to convert it. So I will try. But if you can easilly convert to VB.NET that would be very helpful.
July 1, 2005 at 9:50 am
Copy the code posted by Phil and then go to the URL at the bottom of this message. Before pasting the code, using the drop-down, change the code translation direction to be c# ->VB.net .Then just paste the code into the textbox, wait ~2-3 seconds and then 'presto' the Vb.net code should be at the bottom of the page.
http://www.carlosag.net/Tools/CodeTranslator/Default.aspx
Cheers,
Steve.
July 10, 2005 at 4:51 pm
Awesome! stevefromOZ that's one for the bookmarks! Thank you very much to all who helped.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply