Attachment name save

Hi guys a quick one…So there is an attachment that is sent from a web application into my outlook, then I need to save the attachment to a folder I have created locally but then I need to change it’s name and give it a name of a policy number from an excel file(a variable I already created) e.g…

Below is the example of the naming of the doc

Name of the doc will not always be the same


Use Get outlook mail messages activity.Use Filter by giving mail id or subject
In for loop use save attachment it will save your attachment in your local folder
Then use Rename file activity then it will rename your file

Hi @Anelisa_Bolosha1

Try this. use the below query after Get Outlook mail Messages.

attachmentFileName As String = (From mail In mails
                                    Where mail.Attachments.Count > 0
                                    From attachment In mail.Attachments.Cast(Of Attachment)()
                                    Let attachmentFilePath = "C:\Attachments\" & attachment.Name
                                    Let newAttachmentFilePath = "C:\Attachments\" & policyNumber & ".pdf"
                                    Select File.Move(attachmentFilePath, newAttachmentFilePath)).FirstOrDefault()

Give your directory path where do you want to save.

Hope it helps!!

Hi Anelisa_Bolosha1,
1.Get outlook mail messages.
2.Use save attachment activity to save your attachments .

3. Use an assig activity to save the attachment in the desired path.
4. Use Rename File activity to rename the attachment donwloaded.

Hope it helps!

Hi thank you I get the error

My checkfile variable is a string of array

Hi Anelisa_Bolosha1,
If you want to use the first element of the array then you can use checkfiles.FirstOrDefault(), if you need the second element then you can use checkfiles(1). But if you need to change the name for each element into the array of strings then you can use a for each activity.

So what I want to accomplish is to rename the one I just downloaded from outlook then save in that folder or download and rename after…but keeping in mind there might be other documents already there on the folder.

Hi Anelisa_Bolosha1,
Please check this workflow. (52.1 KB)

Hope it helps you!

1 Like


I hope you know how to read an email…or just use get mail activity

Then pass the output to save attachments activity mails(0) for example

Then use the output of save attachments to rename

Saveatt(0).LocalPath as input and give the name you want to rename


Hi @Anelisa_Bolosha1 ,

How you can identify that file is related to 1276 ?
Is there any criteria to recognise? Please let me know will help you.

Thank you :blush:

Hi@Anil_G, I have already have that activity in place, so it will first check if there are any filrs on a local folder that it wants to download in, if yes then it clears and download the attachment and save it

Could you kindly take a screenshot of the last part on how I should give Saveatt(0).LocalPath as input please

Hi Anelisa_Bolosha1,
I hope you find the solution for your query, If yes Make mark as solution to close the loop.


1 Like

Hi @pavan_kumar5 , so my process is like this:
I have an excel file with policy numbers

I read the first number i take it to a web application to search for an attachment with it,attachment comes back and is sent to my outlook with a different name(dynamic names).
So I am suppose to download the attachment to my local folder and save the attachment with that policy number 1 I read from the excel file.
Bot continues to read another policy number from excel file then save attachment 2 with policy number 2 and so on…

Hi @jose.ordonez1 ,this solution is working but then it only does it for one attachment, it downloads and renames the first one it downloads, when it downloads the second attachment from outlook it breaks:

Please help how can I make sure on the rename every attachment is named according to a different name for my case ,named as policy number it got from excel…please see below the explanation of how the process goes


That might be because of the rename field…you need to use the dynamic name like the invoice number or so that you are getting instead of static name that is aready present


@Anelisa_Bolosha1 initially save attachment in a folder and then use Move File Activity with YourFolderPath\NewName
Note: For every file must have different name in order to save those in a single folder!!

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