How to check if the email has a spreadsheet (xls/xlsx file) as an attachment

@Jebarohith19 Function(variable) is Called as a Lambda Expression, It can Generally be used or accessible where the input is a Collection that can be Iterable.

If i have to Explain what is Actually Happening in the Liq Query above, it’s better if you leanr the Linq using Tutorial Website. But I can tell you What is being performed by the Linq Query.

Since Item is a MailMessage , It Contains Attachments as one of its Methods which provides us the AttachmentCollection , which basically is a List which can be Iterable. Hence we can Iterate and Find the Condition what we need using the “Where” Clause Which accepts a Lambda expression with a Boolean Condition.

Hence the Output of the Linq Query will be the Attachment List Satisfying the Boolean Condition. Since it is a List, We can have a Count of it. I Hope this Explanation is Understandable :sweat_smile:

I suggest you to take basic tutorials of Linq, one of which i have suggested below and understand how the whole process works :smile:

Thank u very much i look onto that tutorial

1 Like

hi
it works for every iteration right?
because now i fi use in loop of mail message it is just taking the condition without excel attachment only

@Jebarohith19 Without Excel Attachments ?

i hve 2 unread mail one containing excel as attachment and anothr contains word as attachment so i will print success message when there i excel attachment
but my problem is it is not taking the excel attachment
spreadsheetpresent.xaml (7.1 KB)

@Jebarohith19 Was it working for other messages which contained Excel as Attachments ?

other messages means messages without excel?
if that so it s just going to the else conditon

Check this link, @Jebarohith19

@Jebarohith19 So it didn’t work for Excel Attachments at all :sweat_smile:

@Jebarohith19 Is it an xlsx or xls Attachment?

yes brother
it doesnt even going into the next loop so immasking is whether the linq expression is for single list?i.e. for one msg only

@Jebarohith19 Actually if you’re using a For Each Loop for the List of Mail Messages, then it Should Iterate the Messages one by one, Then when you use that Expression it will Check if any of the Attachments in that Message has an xlsx Attachment.

this works fine but it is same as my xaml bsut what DID U CHANGE?

yes right i hve done right only but wht did i miss? manish has given the solution which is same as my xaml only

@Jebarohith19 I guess you need to compare and Check, what was the Difference :sweat_smile:

1 Like

@Jebarohith19 I believe you have used this Expression in your xaml instead of What I had suggested :sweat_smile: :
item.Attachments.Where(Function(attach) attach.Name.ToLower= “.xlsx”)

Contains and equals symbol different here too ?

@Jebarohith19 Yes :sweat_smile:, Equals meaning that it Should be exactly equal to .xlsx but it is not, Since your Excel will be in this form “yourFileName.xlsx” hence contains will be the Actual working way.

I hv changed it now thanks and i also made a mistake like variable.tolist.count

1 Like

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