Hi Team,

This is regarding outlook mail once I save the attachment using save attachment activity I want to rename the Excel file by appending digits at the end and read the renamed Excel file. How can I achieve this?


  1. Save Attachment Activity

temp = 0
While temp <= item.Attachments.Count (for multiple)

  1. If File exisits (Path+attachement(0).Name) // replace 0 with temp
    strFileName = Path.GetFileNameWithoutExtension(Path+attachement(0).Name) // replace 0 with temp
    strFileExt = Path.GetExtension(Path+attachement(0).Name) // replace 0 with temp

then Invoke Method → File.Move
params : srcPath : Path+**attachement.Name**
destPath : Path+strFileName+{YOUR DIGITS}+"."+strFileExt


Attachments.xaml (12.1 KB)

Hi Vinay,

It is working only with attachment with different file name. Suppose I need to keep the file in same folder and rename it
by comparing the name of the file in that folder.
Suppose I have 3 excel file in my folder like Vehicle.xlsx, Vehicle1.xlsx, and vehicle2.xlsx I suppose to save the new attachment with vehicleN.xlsx based on the previous excel file name. My next attachment should be vehicle4.xlsx.


How about use regex to get the number by pulling the last created file name?

Regex.Replace(filename, @“\D”, “”);

Hi Vinay,

Thank you. Now I can able to name the file with according to counter. How can I count the number of files in the directory and pass that increment of the counter to the filname as we have appended earlier?
I am using as below:
Directory.GetFiles (“C:\mydirectory”) to get all the files.
How can I count the files inside the directory?


I got it Vinay. Thanks for your time.
mydir of type system.io.directoryinfo
mydir =new System.IO.DirectoryInfo(“Directory name”)

1 Like