how to check if the email has a spreadsheet (xls/xlsx file) as an attachment.
i have used item.Attachments.Where(Function(attach) attach.Name .ToLower= “.xlsx”)
but what will be the output here boolean?
Go through these post!
@Jebarohith19
i dont want to download but i want to check only if it contains excel or not
@Jebarohith19 I guess you can use the Query What you have used above with a bit of modification which will get you the Count of the Attachments having “.xlsx”, So if the Count is greater than 0 , It means there is an Attachment with a .xlsx extension. Below is the Query :
item.Attachments.Where(Function(attach) attach.Name.ToLower.Contains(“.xlsx”)).Count
Thanks @supermanPunch and can u hv any link tht will explain this where query because this query i got from some of the forum posts only or u can explain!?
Wht does function(attach) means?
@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
I suggest you to take basic tutorials of Linq, one of which i have suggested below and understand how the whole process works
Thank u very much i look onto that tutorial
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
@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