If Attachment not in pdf or Xlsx Format, throw error

I am getting email with attachment…I want to check whether my attachment only contain pdf or xlsx format, if mail contain except pdf and xlsx format…It should throw exception.

1 Like

Hey @raja_ias

Kindly you can check the condition as below,

mail.Attachments.Count(Function(att) not {".pdf",".xlsx"}.Contains(path.GetExtension(att.Name))) > 0

If the above is true, you can throw exception !



FYI, another solution:

item.Attachments.All(Function(a) exts.Contains(System.IO.Path.GetExtension(a.Name).ToLower()))