Saving same name attachments

Hi can I please get some help, I am trying to save same name attachments from outlook..even if same name as long as they are attached on the email they should be saved but it’s throwing an error:


These are the docs:

I’m using this activity

From outlook
image

Use a For Each Attachment loop and save attachments manually with a unique nameand in Assign activity:

newFileName = Path.Combine(“Respond_Mails”, System.IO.Path.GetFileNameWithoutExtension(item.Name) & “_” & Now.ToString(“yyyyMMdd_HHmmss”) & Path.GetExtension(attachment.Name))

Then use Save Attachment activity with newFileName.

Cheers

Hello @Anelisa_Bolosha1,

Use a For Each Attachment loop and save attachments manually with a unique nameand in Assign activity:

newFileName = Path.Combine(“Respond_Mails" +
System.IO.Path.GetFileNameWithoutExtension(item.Name) + “_” + Now.ToString(“yyyyMMdd_HHmmss_fff”) + System.IO.Path.GetExtension(item.Name)

Use For Each Attachment instead of Save Attachments and give a unique name:

When different emails may can have 1 attachements with the same name, then it might be an option to incorparate a mail seperation within the target folder path.

Like C:\Users\an…\Respond_Mails\XXX\attachment
XXX can be e.g the messageID from the email, Timestamp…

When one email may have multiple attachments with the same name, then there could be the option available to work on a mailmessage variable copy and modifying the attachment name e.g. along with a counter.

for sure both approaches can also be combined

let us know if further assistance is needed

@anelisa_Bolosha1
If you closely observe the activity properties panel, there is a checkbox to enable “Overwrite Existing”. Select the checkbox and retry.
It will replace your attachment if a file with same name already exists.

Hi apologies for late response but I want all the attachments to be downloaded onto the folder not to be overwritten.

@Anelisa_Bolosha1 I believe using the “Save Attachments” activity it’s not possible to save files with names like Invoice.pdf, Invoice_1.pdf, Invoice_2.pdf if the file already exists in the folder.
You can check if the mail has attachments, then use a For Each loop on mailMessage.Attachments and save each file individually using VB.NET.

You can easily get the code from GPT.
Example:

destinationPath = "C:\\Users\\ManasLenka\\Documents\\Attachments"
fileName = attachment.Name
filePath = Path.Combine(destinationPath, fileName)

’ Extract file parts
fileNameOnly = Path.GetFileNameWithoutExtension(fileName)
extension = Path.GetExtension(fileName)

’ Start counter
counter = 1

’ Keep renaming if file exists
While File.Exists(filePath)
fileName = fileNameOnly & “\_” & counter.ToString() & extension
filePath = Path.Combine(destinationPath, fileName)
counter += 1
End While

’ Save attachment
attachment.SaveAsFile(filePath)