Hello all reporting gurus.
I've been using Telerik reporting in Silverlight for 5 years, acctually with no serious issue.
Now we need to send a report via Mail w/o passing thru printing it to pdf and manually attaching it to a mail. So I've googled a little and found a way thru RepoerRender. The problem is that I'm NOT able to pass any parameter (all I get is a page with just fixed fields and DataSource is not used anytime (I have a breakpoint in report's rptPraticaPreventivo_NeedDataSource event, and it's never hit), so I guess I'm doing it the wrong way.
Can you pls help me in passing parameters the right way?
code I'm using is right after (both in VB and C#). Thank you in advance!
======================================VisualBasic=======================================================
Public Sub SendByMail(nomeRpt As String, parList As String, codTesti As String, adresses As String, sender As String, subj As String, body As String, mailPwd As String)
Dim rptSrc As New InstanceReportSource()
Dim exRpt = Assembly.GetExecutingAssembly
Dim tcw As Type = Type.GetType("UGO_Rpt." + nomeRpt)
Dim rp As New rptPraticaPreventivo
Dim pars() As String = parList.Split(";")
For Each par In pars
Dim idVal() = par.Split("=")
Dim id As String = idVal(0)
Dim val As String = idVal(1)
rptSrc.Parameters.Add(id, val)
Next
rptSrc.ReportDocument = rp
Dim rpt = TryCast(rp, Telerik.Reporting.Report)
Dim reportProcessor As New ReportProcessor()
Dim result As RenderingResult = reportProcessor.RenderReport("PDF", rpt, Nothing)
Dim ms As New MemoryStream(result.DocumentBytes)
ms.Position = 0
Dim attachment As New Attachment(ms, rpt.Name + ".pdf")
Dim msg As New MailMessage(sender, adresses, subj, body)
msg.ReplyToList.Add(sender)
msg.Attachments.Add(attachment)
Dim SmtpServer As New System.Net.Mail.SmtpClient()
Dim netCred As New NetworkCredential
netCred.UserName = "security@mydomain.com"
netCred.Password = mailPwd
SmtpServer.Credentials = netCred
SmtpServer.Port = 587 'Porta standard SMTP/TSL
SmtpServer.Host = "name.server.com"
SmtpServer.SendMailAsync(msg)
End Sub
========================================C#===========================================================
public void SendByMail(string nomeRpt, string parList, string codTesti, string adresses, string sender, string subj, string body, string mailPwd)
{
InstanceReportSource rptSrc = new InstanceReportSource();
dynamic exRpt = Assembly.GetExecutingAssembly;
Type tcw = Type.GetType("UGO_Rpt." + nomeRpt);
rptPraticaPreventivo rp = new rptPraticaPreventivo();
string[] pars = parList.Split(";");
foreach (void par_loopVariable in pars) {
par = par_loopVariable;
[] idVal = par.Split("=");
string id = idVal(0);
string val = idVal(1);
rptSrc.Parameters.Add(id, val);
}
rptSrc.ReportDocument = rp;
dynamic rpt = rp as Telerik.Reporting.Report;
ReportProcessor reportProcessor = new ReportProcessor();
RenderingResult result = reportProcessor.RenderReport("PDF", rpt, null);
MemoryStream ms = new MemoryStream(result.DocumentBytes);
ms.Position = 0;
Attachment attachment = new Attachment(ms, rpt.Name + ".pdf");
MailMessage msg = new MailMessage(sender, adresses, subj, body);
msg.ReplyToList.Add(sender);
msg.Attachments.Add(attachment);
System.Net.Mail.SmtpClient SmtpServer = new System.Net.Mail.SmtpClient();
NetworkCredential netCred = new NetworkCredential();
netCred.UserName = "security@mydomain.com";
netCred.Password = mailPwd;
SmtpServer.Credentials = netCred;
SmtpServer.Port = 587;
//Porta standard SMTP/TSL
SmtpServer.Host = "name.server.com";
SmtpServer.SendMailAsync(msg);
}