How to save only a specific file type using Save Attachment activity?

Hi,

I need to save only excel files from an email attachment. How can do it?

I found there is a Filter property in Save Attachments activity? Is that right option to use? If yes, help me with the Syntax to use Filter property.

7 Likes

Refer this link

1 Like

Hi @vvaidya - Thanks for your quick assistance. But I really need to know about use of filter property in Save attachment activity.

May be someone could tell about that.

Hi @cthamizh ,

In the “Filter” property of the “Get outlook mail message” activity you need to use a syntax like :

“[subject]=‘Uipath demo’”

“[From]=‘Uipath Helpdesk’”

Regards,
V

1 Like

@cthamizh, @Vikas.Jain Actually, the Filter property from Save Mail Attachment will filter on which attachments should be saved. The filter should be in RegEx format.
For your scenario, you can use “.xlsx” filter.

18 Likes

That is what @cthamizh wanted, only xlsx

I just read it. Edited :blush:

Can someone provide a working filter for say .pdf ?
I can save all attachments but not restricted to a specific type e.g. .pdf
I’ve tried these examples below to no avail
… mail.Attachments.Count > 0 AND mail.Attachments.GetType.ToString.Contains(“pdf”)
… mail.Attachments.Count > 0 AND mail.Attachments.tostring.Contains(“pdf”) = true

Does does it mean you need to save all attachments irrespective of file type? In that case you don’t have to check for file type.

If you have to restrict PDF from saving,you can use below regex in save attachment filter to prevent PDF from         downloading.

        (\.|\/)(?!PDF|pdf).*

You could also validate in below way to see if any of your attachment is PDF.

If (item.Attachments.Where(Function(x) x.Name.Contains(“.pdf”)).Count >0)

ps: my mobile posting sucks!

10 Likes

Thanks for the reply @vvaidya
At this stage I don’t know how to include regex into a filter (i.e. what comes before it).
The second suggestion would save all attachments so long as 1 x of the attachments was of target type.
Often there are signature elements like .png as well as a true attachmnet life a .csv or .pdf.

I adapted my solution from this post How to save perticular file from outlook, when the attachments contains multiple files - #3 by aksh1yadav thanks @aksh1yadav

Specifically I used this filter as a condition

Path.GetExtension(attachmnt.Name).Contains(“pdf”) = True Or Path.GetExtension(attachmnt.Name).Contains(“xls”) = True Or Path.GetExtension(attachmnt.Name).Contains(“csv”) = True Or Path.GetExtension(attachmnt.Name).Contains(“txt”) = True Or Path.GetExtension(attachmnt.Name).Contains(“csv”) = True

4 Likes

Hi @cthamizh,

If you want to download only Excel files, use this in the Filter property of the Save Attachment Activity.

".*(.xlsx|.XLSX|.xls|.xls)"

It will download only excel file.

28 Likes