要做到这一点,您需要像下面那样利用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
谁将文件保存到文件系统?你或你的同事提供的'黑盒'解决方案? –