I am using Rotativa. MVC to generate a PDF from a view, so I can send an email with the PDF as an attachment. The following code does so:
var p = ControllerContext;
var h = new ViewAsPdf("Index") { FileName = "TestViewAsPdfHm.pdf" };
var hmm = h.BuildPdf(p);
var memStream2 = new SysIO.MemoryStream(hmm);
MailMessage mm = new MailMessage("From@gmail.com", "To@gmail.com");
mm.IsBodyHtml = true;
mm.Attachments.Add(new Attachment(memStream2, "BuildPdfOption.pdf"));
My question is "How do I obtain a PDF file saved i.e. in my MVC application's Content/Pdf folder, from within in c# code, so I can attach it to an email in the same manner?" I have tried many times with file,stream readers and with HttpContext.Server.MapPath, but without success. Using the MapPath option just had a textual document in the email that I couldn't open.