我正在嘗試使用Reporting Services 2005 webservice生成pdf。我有pdf生成部分工作,但我不知道如何得到一個「物理」pdf,我可以附加到一封電子郵件之前發送它的方式。通過web服務生成PDF並將其作爲附件通過電子郵件發送出去
我所創建的PDF此指南如下: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();
}
從這一點我能夠調用RenderPdf方法,我提示打開/保存/取消的文件。我知道如何發送帶有硬盤附件的電子郵件,但我不知道如何將結果[]轉換爲我可以處理的格式。
在此先感謝
我有類似的SO看看http://stackoverflow.com/questions/919829/send-sql-report-in-e-mail-attachment-using-c-and-asp-net – adopilot