How to get the filename of attachment?

How could I get the filename of attachment without saving the attachment? I want to compare that name through “if” condition.
There are options in coding like item.attachment.display name or item.attachment.filename (for each item in mailbox loop) but I could not find either in UIPath.
Please help here.


Hi @igul,

If your email contains just one attachment you could use the following code to get its name:
attachmentName = CType(item.Attachments.FirstOrDefault, Attachment).Name

Kindly check it at the example below:
Main.xaml (1.2 KB)

Also, please confirm if it’s what you were expecting, otherwise I’ll try to help either way.


Thanks. It worked fine for me.


I try this on an assign function but it didn’t work:
This error usually occurs when using a variable with no set value.

What if there are multiple attachments?




The above logic is giving me the type of the attachment and not the name.


are you refering to write line then change it to attachment.Name

i cannot find the .Name methode?

1 Like

for that you have to change the for each argument type as well pal.

to which type?

with this System.Net.Mail.Attachment


thank you,

now i want ti save it in a folder with the same name

Well just use that name and use “Create Directory” activity and pass it the path with the attachment name you will get.
and then use “save attachment” activity and pass that attachment object with the path of folder.

thank you, but it create download the attachement in a same folder

Hey @abdel

Well try this and let me know :slight_smile: abdel_sample.xaml (17.9 KB)

Note- it is Creating attachment and saving them inside “D:\Sample” then opening it.

Feel free to modify it as per your needs like path.


1 Like

thank you aksh,

i got the following error when i had tested your workflow:

it did not find GetFileNameWithoutExtension method!

Well import “System.IO” namespace then try it. if still not able to make it work then give it a try with this : “System.IO.Path.GetFileNameWithoutExtension” and let me know :slight_smile:


thank you, it works, but i had designed a process that get some data from the attached pdf,

for exemple if i had two received scanned pdf i must get the information using scrape relative activity