c# - Get file to send as attachment from byte array -
I have an ASP.NET MVC application that has a list of recipients given a specific "project" I get this information from a report using SQL Server Reporting Services (SSRS).
I have not used SSR before, but I got some code from a colleague where they used it. What he does with the report he downloads it to the client's machine in the browser, so if I do not do this, then I sit with a byte array with report data.
Is there a way that I can send files as an attachment on file system without first writing them physically? The report will dry out in Excel format or PDF.
Edit: I am using To do this, you will need to take advantage of this type of SSRS ReportManager API. ReadFully and send the method NB: SendAsync calls so that you are not waiting to send the email completely before sending the email to the server completely. SmtpClient to send an email.
string strReportUser = "RSUserName"; String strReportUserPW = "MySecretPassword"; String strReportUserDomain = "DomainName"; String sTargetURL = "http: // SqlServer / ReportServer?" + "/ MyReportFolder / Report1 & amp; rs: command = render & amp; amp; amp; 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 fold around and send it as feedback .. ReadFullyAndSend (fStream);
public static blank ReadFullyAndSend (stream input) {(MemoryStream MS = New MemoryStream ()) using {input.CopyTo (ms); Mail message message = new mailmessage ("from@foo.com", "too@foo.com"); 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 network credentials ("EFU", "bar"); Smtp.SendAsync (message, empty); }}
Comments
Post a Comment