Click here to Skip to main content
14,982,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
>I have c# application that reads email, i read xml and pdf file when i have no Embedded attachments. When i tried to read pdf from Embedded attachement, the code only reads .bmp, jpg files. My code

string strFiltro = String.Format("SINCE {0}-{1}-{2} BEFORE {3}-{4}-{5} {6} ",
                                       strDiaInicial,
                                       strMesInicial,
                                       strAnioInicial,
                                       strDiaFinal,
                                       strMesFinal,
                                       strAnioFinal,
                                       (this.MensajesNoLeidos == true ? "UNSEEN" : "ALL"));


            IEnumerable<Message> mensajesFiltrados = folder.Search(strFiltro/*MessageFetchMode.Full,10*/);
mensajesFiltrados = mensajesFiltrados.Where(x => x.Attachments.Count() > 0 || x.EmbeddedResources.Count() > 0);

      foreach (Message message in mensajesFiltrados)
            {
              if (message.Attachments.Count() > 0)
                    ArchivosAdjuntosFiltrados = message.Attachments.Where(x => x.ContentType.Name.ToLower().Contains(".pdf") ||                                                      x.ContentType.Name.ToLower().Contains(".xml"));
                    resultado[0] = resultado[0] + ArchivosAdjuntosFiltrados.Count();
            }else
                 {
                  if (message.EmbeddedResources.Count() > 0)
                    {
//never get Embedded pdf or xml files ArchivosAdjuntosFiltrados = message.EmbeddedResources.Where(x => x.ContentType.Name.Contains(".pdf") || x.ContentType.Name.Contains(".xml"));

                     }
                 }

       foreach (Attachment atachemtn in ArchivosAdjuntosFiltrados)
                {
                    strNombreArchivo = atachemtn.FileName;
String attachData = atachemtn.GetTextData().Replace('-', '+'); attachData = attachData.Replace('_', '/');

                if (intPosicion > 0)
                    {
                        attachData = attachData.Substring(0, attachData.Length - 31);
                    }


                    if (strNombreArchivo != String.Empty)
                    {
                        
                        if (File.Exists(Path.Combine(strRutaDescargas, atachemtn.FileName)) == true)
                        {
                            if (pBlnSobreescribirArchivos == true)
                            {
                              
                                byte[] data = Convert.FromBase64String(attachData);
                                File.WriteAllBytes(Path.Combine(this.strRutaDescargas, strNombreArchivo), data);
}

Any help will be appreciated..


What I have tried:

I can only read jpg image, not xml and pdf
Posted
Comments
Gerry Schmitz 12-May-21 20:43pm
   
So? Don't use Embedded for pdf's.
KlingCan 19-May-21 10:16am
   
What can i use instead of Embedded for pdf?
BillWoodruff 12-May-21 21:02pm
   
is this your own code ?
KlingCan 19-May-21 10:17am
   
Yes is my own code
BillWoodruff 19-May-21 10:25am
   
you need to set break-points and single-step through your code: i suggest running it on a test case where a message has one .pdf attachment.

as you hit each break-point, examine the state of variables and note where values seem in error.

please explain in more detail: "read pdf from Embedded attachement" ... what does "read" mean ?
KlingCan 21-May-21 12:05pm
   
message object

I have 4 attachment, but i only se 3, i dont see pdf named test.pdf

ContentId = "lnk0"
ContentType = {application/octet-stream; name=clip_image001.png}

ContentId = "lnk1"
ContentType = {application/octet-stream; name=clip_image001.png}

ContentId = "lnk2"
ContentType = {application/octet-stream; name=clip_image002.png}

ContentId = "lnk3"
ContentType = {application/octet-stream; name=clip_image002.png}
KlingCan 2-Jun-21 10:49am
   
Any other idea?
KlingCan 23-Jun-21 9:25am
   
I still working in my project discovered when i have embedded attachment and not embedded attachment the program only reads embedded attachment.
Any idea?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900