I am trying to generate a pdf using the Reporting services 2005 webservice. I have the pdf generation part working, but I am not sure how to get a “physical” pdf that I can attach to an email before sending it on its way.
I have created the pdf following this guide: http://www.codeproject.com/KB/reporting-services/PDFUsingSQLRepServices.aspx
public void RenderPdf(string rptMemo, string emailAddress )
{
// Prepare Render arguments
string historyID = null;
string deviceInfo = null;
string format = "PDF";
Byte[] results;
string encoding = String.Empty;
string mimeType = String.Empty;
string extension = String.Empty;
Rse2005.Warning[] warnings = null;
string[] streamIDs = null;
//Credentials that will be passed to reporting services
Rse2005.ReportExecutionService rsExec = new Rse2005.ReportExecutionService();
rsExec.Credentials = new NetworkCredential("username", "password", "domain");
//Report is called "Report1", it takes a parameter called "Id"
Rse2005.ExecutionInfo ei = rsExec.LoadReport("/Reports/Report1", historyID);
Rse2005.ParameterValue[] rptParameters = new Rse2005.ParameterValue[1];
rptParameters[0] = new Rse2005.ParameterValue();
rptParameters[0].Name = "Id";
rptParameters[0].Value = RptMemo;
//render the PDF
rsExec.SetExecutionParameters(rptParameters, "en-us");
results = rsExec.Render(format, deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=DetailedQuote.pdf");
HttpContext.Current.Response.OutputStream.Write(results, 0, results.Length);
//This is very important if you want to directly download from stream instead of file.
HttpContext.Current.Response.End();
}
From this point I am able to call the RenderPdf method and I am prompted to open/save/cancel the file. I understand how to send an email with an attachment from the harddrive but I am not sure how to make results[] into a format I can handle.
thanks in advance
You should save the pdf to disk or memory and then use System.Net.Mail to send it
Here is a quick link from google.
http://www.systemnetmail.com/faq/3.4.2.aspx
You can write results from your example to a memory stream like so
You should remove these 3 lines from your code