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 SmtpClient to send an email.

To do this, you will need to take advantage of this type of SSRS ReportManager API.

  1. Read the report from the web service with the SSRs first
  2. Instead of saving the server or the client, read the file in memory
  3. MemoryStream object directly e Send -mail to server

      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);   

    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.

      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

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -