How to attach a PDF file encoded in base 64

0

I am developing a solution that consults PDF records from a WEB service. The result of the consumption of this service can be encoded and stored as PDF:

File.WriteAllBytes(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\prueba_" + cf.id_identificador + ".pdf", Convert.FromBase64String(tRespuesta.PDFResultado));

This PDF must be sent by email, which could be done with the same route that was saved ...

But saving the file and then consulting it greatly increases the time when the number of times this process is repeated is very large.

Is there any way to directly attach the result of the webservice without saving the file?

MailMessage email = new MailMessage();
email.To.Add(new MailAddress(destino));
email.From = new MailAddress("[email protected]");
email.Subject = "Asunto( " + DateTime.Now.ToString("dd / MMM / yyy hh:mm:ss") + " ) ";
//email.Attachments.Add();
email.Body = "Do not reply.";
email.IsBodyHtml = false;
email.Priority = MailPriority.High;
    
asked by German AT 04.05.2017 в 01:33
source

1 answer

0

You've already tried with TransferEncoding

Attachment pdfb64= new Attachment(base64String);
pdfb64.TransferEncoding = TransferEncoding.Base64;
email.Attachments.Add(pdfb64);
    
answered by 04.05.2017 / 02:51
source