public class MyReportRenderer
{
private rs2005.ReportingService2005 rs;
private rs2005Execution.ReportExecutionService rsExec;
//string casenumberKey;
public void RenderTest()
{
string HistoryID = null;
string deviceInfo = null;
string encoding = String.Empty;
string mimeType = String.Empty;
string extension = String.Empty;
rs2005Execution.Warning[] warnings = null;
string[] streamIDs = null;
rs = new rs2005.ReportingService2005();
rsExec = new rs2005Execution.ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = "http://216.40.232.82/ReportServer_DEVELOPMENT/ReportService2005.asmx";
rsExec.Url = "http://216.40.232.82/ReportServer_DEVELOPMENT/ReportExecution2005.asmx";
//// pass parameters
try
{
// Get if any parameters needed.
// Load the selected report.
rsExec.LoadReport("/LawDept/LawDeptTIC", HistoryID);
// Prepare report parameter.
// Set the parameters for the report needed.
rs2005Execution.ParameterValue[] parameters = new rs2005Execution.ParameterValue[3];
parameters[0] = new rs2005Execution.ParameterValue();
parameters[0].Name = "CaseNumberKey";
parameters[0].Value = "000002";
//parameters[1] = new rs2005Execution.ParameterValue();
//parameters[1].Name = "ReportMonth";
//parameters[1].Value = "6"; // June
//parameters[2] = new rs2005Execution.ParameterValue();
//parameters[2].Name = "ReportYear";
//parameters[2].Value = "2004";
rsExec.SetExecutionParameters(parameters, "en-us");
// get pdf of report
Byte[] results = rsExec.Render("PDF", deviceInfo,
out extension, out encoding,
out mimeType, out warnings, out streamIDs);
MailMessage message = new MailMessage("[email protected]", "[email protected]", "Hello", "This is a test");
SmtpClient emailClient = new SmtpClient("localhost");
message.Attachments.Add(new Attachment(new MemoryStream(results), String.Format("{0}_DocumentSavingsReport.pdf", "ReportName")));
emailClient.Send(message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
我會在我需要它執行時調用這個?如何撥打以下電話?
-1「不是一個真正的問題」。不要發佈一個代碼塊(並期待一個奇蹟般的正確猜測),考慮發佈上下文*和一個完整的深思熟慮的問題*。它看起來像是在使用RS,所以有一個開始 - 但是當這個運行時有什麼要求/期望? – 2011-06-02 02:00:34
@pst嗯,當我完成其餘部分的編寫時,它需要在Windows服務在表中找到記錄時運行,並且需要將CaseNumberKey作爲參數傳遞。現在讓我們說點擊button1的時候。在進入下一部分之前,我需要能夠測試它,但我不完全確定如何調用它。 – korrowan 2011-06-02 02:04:23