How to get the filename of attachment?

outlook

#1

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.


Saving attachements from outlook, with new name
How to read attachment files names of all unread mails?
How to get the an email attachement
#2

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.


#3

Thanks. It worked fine for me.


#4

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


#5

What if there are multiple attachments?


#6


#7

@vvaidya

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


#8

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


#9

i cannot find the .Name methode?


#10

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


#11

to which type?


#12

with this System.Net.Mail.Attachment


#13

thank you,

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


#14

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.


#15

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


#16

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.

Regards…!!
Aksh


#17

thank you aksh,

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

it did not find GetFileNameWithoutExtension method!


#18

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:

Regards…!!
Aksh


#19

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