To find the latest file and download if it contains specific file name condition

Hi All,

I want to download the latest file that contains the condition from the below data table.

I am getting the max date from data table and If I compare each row with below conditions its becoming null with no condition satisfied .For example the max date here is 11/22/2023 2:27 pm but it does not contain below condition.

str_attached_files_name.Contains(“SOW”) or str_attached_files_name.Contains(“Order Form”) or str_attached_files_name.Contains(“OF”)

I need file with latest date and below condition and then click on download

str_attached_files_name.Contains(“SOW”) or str_attached_files_name.Contains(“Order Form”) or str_attached_files_name.Contains(“OF”)

Hi @dutta.marina

Can you try below Linq query

str_LatestFile = dt.AsEnumerable().
                 Where(Function(row) row("FileName").ToString().Contains("SOW") OrElse
                                     row("FileName").ToString().Contains("Order Form") OrElse
                                     row("FileName").ToString().Contains("OF")).
                 OrderByDescending(Function(row) DateTime.Parse(row("Date").ToString())).
                 Select(Function(row) row("FileName").ToString()).
                 FirstOrDefault()

Regards,

1 Like

@lrtetala

In the below condition it should download order form also, but it only downloaded SOW

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