First process with studio - getting the attachment name

Hi :wave:, I am new the UiPath and recently started following the RPA associate learning path. Currently I am at the ‘Build your first process with studio’ module.

While following the ‘Building the workflow - part 2’ video, I found that when referencing the ‘workbook path’ in the ‘Excel application scope’ activity, it uses the path as "Invoices"+RetrievedEmail.Attachments.First.Name.

This works fine and it retrieve the attachment name as expected. However, my question is that when I type the above path, until the ‘First’ it suggests me the options to select but it does not suggest ‘Name’. I am trying to understand why this is the case.

I have tried changing the ‘RetrievedEmail’ argument type to ‘System.Net.Mail.Attachment’ and ‘System.Net.Mail.MailMessage’ and result was the same.

Thank you!

HI @Thusitha_Bandara

RetrievedEmail is an object of the System.Net.Mail.MailMessage class, which represents an email message.
Attachments is a property of the MailMessage class that returns a collection of Attachment objects. Each Attachment object represents an email attachment.

It doesn’t suggest ‘Name’ after ‘First’ is that the IntelliSense feature in Studio doesn’t have complete support for chaining multiple methods or properties from different classes. It provides suggestions based on the immediate properties and methods of the variable you are working with. In this case, ‘First’ returns an object of type Attachment , and IntelliSense doesn’t go further to suggest the properties of the Attachment class.

However, even though IntelliSense doesn’t suggest ‘Name,’ you can still manually type ‘.Name’ after ‘First’ knowing that it is a valid property of the Attachment object returned by the ‘First’ method.

1 Like

Hi,

For now, can you try to add () after First? As First is method, more precisely it should be written as First() and it will help intellisense feature.

Regards,

1 Like

@Thusitha_Bandara

The reason why the UiPath Activities panel does not suggest the “Name” property of the “RetrievedEmail.Attachments.First” variable is because the “Name” property is not a public property of the “System.Net.Mail.Attachment” class.

The “Name” property is a read-only property that is only available to the code that created the attachment. This means that the UiPath Activities panel cannot see the “Name” property, so it cannot suggest it as a possible value for the “workbook path” property of the “Excel Application Scope” activity.

To work around this, you can use the “GetFileName” method of the “System.Net.Mail.Attachment” class to get the name of the attachment. The “GetFileName” method returns a string that contains the full path and filename of the attachment.

For example, the following code will get the name of the first attachment in the “RetrievedEmail” variable and use it as the workbook path for the “Excel Application Scope” activity:

string attachmentName = RetrievedEmail.Attachments.First.GetFileName(); ExcelApplicationScope excelAppScope = new ExcelApplicationScope(attachmentName);

1 Like