Need to check if attachment filename is of type ".pdf" as part of "If" statement

I need to save email attachments only if the following conditions apply for the If statement:

  1. “listMailmsg(N).Attachments.Count>0” AND
  2. the attachments need to be only of type “.pdf”

I don’t know what is the syntax to check that the filename for the attachment is “.pdf”

N is a counter for a loop which needs to go through a list of mail messages and save only pdf files for VALID EMAILS to a folder OR if there are no attachments or a VALID EMAIL then it needs to send out a message informing the user that there is no attachment.

The workflow is not working at the moment though I will attach it, I just need to specify these two arguments for the “If” statement.Main.xaml (90.9 KB) project.json (985 Bytes)

this is perfect while for this

the condition should be like
listMailmsg(N).Attachments.Name.ToString.Contains(".pdf")

Hope this would help you
Cheers @Taariq

Hi,

When you save the atachments, you receive as output a “IEnumerable” where every single value is a Complete path of every single File. So you can ask in the If (inside a for each item): attachment(0).EndsWith (".pdf")

It should work.

Hi @Taariq

Check this post as well

Thanks
Ashwin S

1 Like

I cannot find the “.Name” after the “.Attachments”

There are different attachment types, “.png”, “.pdf”, needs to save only the “.pdf”

Is there no other way to do this because the “Else” part of the “If” is also quite important as it needs to send out an error email to the client if there has not been a “.pdf” attachment found? So if I only have the “listMailmsg(N).Attachments.Count>0” as the argument then it does not execute the else part where for instance it finds a “.png” attachment (being a logo, etc.) btw why does Ui Path not just save the actual attachment only? Why is it saving things on the email that have not been directly attached?

So I need to be able to identify the attachment type as well and get that information as string/Boolean if possible.

Okay I tried the “If” within the “For each” and I am unable to get the “.EndsWith” after.

1 Like

if possible can i have on the property panel of For each activity
Cheers @Taariq

Refer attached. Is iterating through “System.Net.Mail.AttachmentCollection”

Hi,
How about this:

listMailmsg(N).Attachments.Where(function(x) x.Name.EndsWith(“pdf”)).Count > 0

(not tested, though) :frowning:

Cheers

1 Like

Thanks @J0ska, this worked well. Please can you explain this part:

Where(function(x) x.Name.EndsWith(“pdf”))

This is so called ‘lambda expression’
Find more in Stack Owerflow https://stackoverflow.com/questions/18317333/how-to-write-a-vb-net-lambda-expression
or in MS reference https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/how-to-create-a-lambda-expression#example

Cheers

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.