Send email attchment with dynamic name

Hello,
I need to send an e-mail with an attachment that has dynamic name , the date of the current day in this format MM_dd_yyyy how can I define the path for that ?

the file has .xlsx extension if it matters

"File pathway " + date.today.tostring(“MM_dd_yyyy”) + “.xlsx”

Hi!

Try like this!

check for the file exists. if file is exists inside the folder. do like this

  1. strFolderPath(ArrayOfString)=Directory.getfiles(“c://FolderPath”,*.xlsx)

  2. strNewFileName=strFolderPath+DateTime.now.ToString(“MM_dd-yyy”).ToString

  3. For each(TypeArgument->String) mention strFolderPath

  4. Take SMTP

  5. In the attachments mention StrNewFileName

Regards,

in the send outlook mail message ; in attach file I defined the value like this : “c://FolderPath”+date.today.tostring("MM_dd_yyy)
and it gives me the error that cannot find the file verify the path and file name are correct

Hello @mihai.godeanu

It better to print it in a message box or console and validate the path once manually before using in the attach document. Make user you have added the “.xlsx” to the file path after adding the file name.

@mihai.godeanu
u can give like this
“c:\FolderPath”+Now.toString(“MM_dd_yyyy”)+".xlsx"

not working

this doesn’t work

@mihai.godeanu can u attach a screenshot of your code?

it’s the same error saying that could not found the file , check the path and filename, if I put the path of the file direct it works, but the name of the file will change every time the robot will run

Hey @mihai.godeanu

You need to use Rename File activity and change the filename present in the local C folder post which you can attach the same file to the outlook activity!

Hope this helps.

Thanks
#nK

@mihai.godeanu
“C:\Users\sheik asif\Documents\UiPath\BlankProcess4”+“RPA “+Now.ToString(“dd-MM-yyyy”)+”.xlsx”

its working for me

Here is the file path iam using
“C:\Users\sheik asif\Documents\UiPath\BlankProcess4\RPA 23-05-2022.xlsx”