Group by in list

Currently i have a list containing file path
image

would like to group by Customer (A or B) for attachment and email sending purpose

End result:
Customer A receives (in a single email)
D:\2023\A_1.pdf
D:\2023\A_2.pdf

Customer B receives D:\2023\B_1.pdf

Currently facing issue where by when email being sent out
Customer A will receive 2 separate email:
Email 1 contains D:\2023\A_1.pdf
Email 2 contains D:\2023\A_2.pdf

Hi,

Can you try the following sample?

dict = files.GroupBy(Function(f) System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileNameWithoutExtension(f),"^[A-Za-z0-9 ]+").Value).ToDictionary(Function(g) g.Key,Function(g) g.ToList)

Sample20230620-3.zip (3.2 KB)

Regards,

in general we would group the data (we assume that it is a string list)
for the customer grouping we can use a regex:
grafik

Assign Activity:
Groups | List(Of List(Of String)) =

(From x in YourStringList
Let c = System.Text.RegularExpressions.Regex.Match(x,"(?<=\\).?(?=_)").Value.Trim.ToUpper
Group x by k=c into grp=Group
Select gl=grp.ToList).toList

Outer groups are the customers, inner group are the customer related files

Then loop over the outer list and use the looped inner list for your customer related processing

Hi @Yoichi
I am currently using this activity to append some columns to get my file path in a for loop

image

Something like this for your reference
image

my for each loop does not seems to be the same as what you have, version difference?
image

Hi,

If possible,can you share your project as file?

Regards,

would be a little tough as it contains some company info… :frowning:

let me try and do a mock up

Test.zip (6.0 MB)

original attachment is in PDF mock up done in words

Hi,

In this case, as your workflow seems mostly completed, it might be better to add just the following expression, then send them as attachment. How about this?

files = System.IO.Directory.GetFiles("yourPath",yourCompanyName+"_*.pdf")

Regards,

1 recipient to 1 attachment is working,
problems comes when 1 recipient to multiple attachment
instead of sending 1 email with multiple attachment it is sending multiple email with 1 attachment

e.g
Customer A will receive 2 separate email:
Email 1 contains D:\2023\A_1.pdf
Email 2 contains D:\2023\A_2.pdf

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