要做到這一點,您需要像下面那樣利用SSRS ReportManager API。
- 從Web服務的報告與SSRS
- 首先讀取文件讀入到內存,而不是保存到服務器或客戶端
- 發送MemoryStream的對象直接到電子郵件服務器。
Reporting services: Get the PDF of a generated report How to send an email with attachments using SmtpClient.SendAsync?
string strReportUser = "RSUserName";
string strReportUserPW = "MySecretPassword";
string strReportUserDomain = "DomainName";
string sTargetURL = "http://SqlServer/ReportServer?" +
"/MyReportFolder/Report1&rs:Command=Render&rs:format=PDF&ReportParam=" +
ParamValue;
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(sTargetURL);
req.PreAuthenticate = true;
req.Credentials = new System.Net.NetworkCredential(
strReportUser,
strReportUserPW,
strReportUserDomain);
HttpWebResponse HttpWResp = (HttpWebResponse)req.GetResponse();
Stream fStream = HttpWResp.GetResponseStream();
HttpWResp.Close();
//Now turn around and send this as the response..
ReadFullyAndSend(fStream);
ReadFullyAnd發送方法。 注意:SendAsync調用,因此您不會等待服務器完全發送電子郵件,然後才能使用戶退出點頭。
public static void ReadFullyAndSend(Stream input)
{
using (MemoryStream ms = new MemoryStream())
{
input.CopyTo(ms);
MailMessage message = new MailMessage("[email protected]", "[email protected]");
Attachment attachment = new Attachment(ms, "my attachment",, "application/vnd.ms-excel");
message.Attachments.Add(attachment);
message.Body = "This is an async test.";
SmtpClient smtp = new SmtpClient("localhost");
smtp.Credentials = new NetworkCredential("foo", "bar");
smtp.SendAsync(message, null);
}
}
您有ASP.NET MVC(版本?)Web服務器上傳文件,並且您想將上傳的文件發送到(SMTP?)您的電子郵件地址列表? –
@JossefHarush:不,我沒有文件上傳控件。我要附加的文件來自從SQL報告服務器檢索到的SSRS報告。我可以在代碼中配置以各種格式檢索報告,但我將使用xsl或pdf。 – Carel
誰將文件保存到文件系統?你或你的同事提供的'黑盒'解決方案? –