Outlook File Wildcard

Hello Guys,

I want to attach a File to an E-Mail. The last couple of digits always change with each download.

Now I already read, that you cant use wildcards with filenames.

I have found this: Attaching file to Outlook using wildcard - Help / Studio - UiPath Community Forum

There a solution is offered with System.IO.Directory.GetFiles(“XXX”).Last. My issue is that it takes file that is not even in the directory. Any ideas what the issue might be?

You used the right method but wrong parameters.

GetFiles(directory path, file name pattern)

In this case, you can use wildcard in file name pattern like unkown_*.txt

Make sure you’re passing the actual download folder and asking for the newest file, not just the last one alphabetically:

e.g. if the latest file is stored in C:\Users\VLC\Downloads

latestFile = Directory.GetFiles("C:\Users\VLC\Downloads", "Report_*.pdf") _
              .OrderByDescending(Function(f) New FileInfo(f).LastWriteTime) _
              .First()

Then feed latestFile into the Attachments property of Send Outlook Mail Message.

If the file is still being written when the activity runs, add a Wait for Download before this step.

@VLC,

You can store the exact file name while downloading and pass that as an attachment.

I like the idea but i dont think I can. There is no pop up for the file I have downloaded. Its just in downloads

@VLC,

You can enable Always ask where to download and use the desired folder and the file name you want.

Here is how to enable this in chrome browser:

I just tried to put in the full file name but I got the following error message:
Multiple Assign: ‘System.IO.Directory.GetFiles(“C:\Users\castvin\Downloads\GD_GMMMLDFS_LAG_BES_TAEGL_FS06062025083950223.xlsx”)’ kann nicht zu ‘Datei’ zugewiesen werden.

I wonder because I copy the Filepath directly from the file…

Hi Ashok, yes I tried that already but I am having issues working with the pop up which arrives. UI Path cant find it after clicking the dowload button

@VLC,

To handle that save as popup, you will have to use a separate Use application/browser activity, inside it use Type Into and click activity to save the file.

1 Like

@VLC

The error happens because Directory.GetFiles requires a folder path, not a full file path. You should pass the folder path and a search pattern (with wildcards), not the exact file name.
Try to use like below,

files = Directory.GetFiles(“C:\Users\castvin\Downloads”, “GD_GMMMLDFS_LAG_BES_TAEGL_FS*.xlsx”)

latestFile = files.OrderByDescending(Function(f) New FileInfo(f).LastWriteTime).First()