How to write a query for Filter by filename property in save email attachments activity

I am using save email attachments activity to download the attachments.

My scenario is :
Save the required attachments from Email. If Pdf is available, we are downloading the Pdf files, else download excel file.

for above scenario i gave below code If(currentOffice365Message.Attachments.Any(Function(x) path.GetExtension(x.Name).ToString.ToLower.Equals(.pdf)),.pdf,“.xls”)

It is working if attachment extension is .pdf or .xls.
If attachment extension is .PDF means it is not working. How to fix this.

1 Like

You were close but Try This

If(currentOffice365Message.Attachments.Any(Function(x) Path.GetExtension(x.Name).ToLower() = “.pdf”), “.pdf”, “.xls”)

If you find it as Solution then mark it as SOLUTION

Happy Automation

Hi @balanirmalkumar.s
Try this,

If(currentOffice365Message.Attachments.Any(Function(x) Path.GetExtension(x.Name).ToLower = “.pdf”), “.pdf”, “.xls”)

Also check this,

If(currentOffice365Message.Attachments.Any(Function(x) System.Text.RegularExpressions.Regex.IsMatch(x.Name, “.pdf$”, RegexOptions.IgnoreCase)), “.pdf”, “.xls”)

It is not working. I am not getting any attchment.

I tried with this query If(currentOffice365Message.Attachments.Any(Function(x) System.Text.RegularExpressions.Regex.IsMatch(x.Name, “.pdf$”, RegexOptions.IgnoreCase)), “.pdf”, “.xls”)

It is not working.

@balanirmalkumar.s
What error are you getting pls share screenshot for more clarity,
Check this ,

If(currentOffice365Message.Attachments.Any(Function(x) System.Text.RegularExpressions.Regex.IsMatch(x.Name, “.pdf$”, System.Text.RegularExpressions.RegexOptions.IgnoreCase)), “.pdf”, “.xls”)

If(currentOffice365Message.Attachments.Any(Function(x) Path.GetExtension(x.Name).ToLowerInvariant() = “.pdf”), “.pdf”, “.xls”)

Try this

Cheers

The problem isn’t the expression, it’s that you only have designated the lower case extensions in the resulting filter and have not defined the filter properly.

If(currentOffice365Message.Attachments.Any(Function(x) path.GetExtension(x.Name).ToString.ToLower.Contains("pdf")),"*.pdf|*.PDF","*.xls|*.XLS|*.xlsx|*.XLSX")