UI path overwriting .pdf attachments with same name while downloading from outlook


I am not sure whether this was asked before, however i tried searching and did not get exact solution.

I am trying to download pdf attachments from certain mails with certain subject lines, things work fine except that UI path is overwriting the attachments with the same name(keeping the latest one only).I tried using time stamp, yes that works but few attachments still are having the same name as defined whereas majority of them are coming with time stamps(i don’t know why it does not put time stamp for the starting few attachments).
Is there any way without using time stamp that UI path automatically put suffix for every attachment with same name and does not overwrite.
eg.-If an attachment has name xyz and if another attachment comes it should be named xyz_01 and not overwritten.


you can go through all the Files in a Directory with a For-Each Activity and Directory.GetFiles(“Path-To-Directory”) in the Value Section. Then you compare the Values(Strings) which are already there and then pick the Number that was not yet used.


1 Like

You could set up a counter for each attachment that’s downloaded, and increment by 1. It would add a number onto the end of all files, not just the duplicates, but it would guarantee none have the same name.

Hi Subhani,

  1. use save attachment activity then name the file with timestamp with hh/mm/ss

  2. if it is in loop give some delay 1 or 2 seconds

Thanks @rajsekhar @KEntwistle @BobBuilder for you help, combination of all the 3 solutions helped me achieve what i wanted.
Thanks again.

Hi, I have a similar issue, the only thing is that I don’t know how to rename the file before the save attachment, because the save attachment activity downloads all at once, how can I either rename them before downloading or downloading them one by one and rename them in that process

As far as I know you cannot rename before downloading them. We get round it by downloading all to a folder and then iterating through the folder with a for each.

We found a way using an invoke code and some C#, when using this method you only pass the attachment as an argument to the invoke code activity and the path where you want the file to go there’s when you actually rename the file and that’s the Destination Variable that you pass as an argument as well

byte allBytes = new byte[item.ContentStream.Length];
int bytesRead = item.ContentStream.Read(allBytes, 0, (int)item.ContentStream.Length);
string destinationFile = @Destination;
File.WriteAllBytes(destinationFile, allBytes);

Hi ! How do you give a delay of 1 or 2 seconds to the loop?

Not sure why you want to do that but you can use the delay activity inside the loop and give delay time ss 00:00:01.

1 Like

works thanks!

How do I use it?
It is not very clear to me

Hello @Beatriz_Eugenia_Duqu ,

Interesting thig from my check is if you’re using the UiPath Studio with C# project, the attachment files with the same name will be saved with an appended number (_1,_2,_3…).

I have also a project created in VB.
To avoid the overwrite issue, I pass in the filter, the attachment name


I hope it helps.


1 Like


Could you please share this complete image with me?
To see the configuration thank you
Uploading: image.png…

Like this:

1 Like

Very tanks