I have designed a workflow in which I am extracting the data from Gmail account and saving the attachment, and writing all the extracted data into excel. For eg. Excel file can contain, Name, emailid, body of email, Date and Attachment Name. So, bot will extract the data and write into excel. If it has attachment, it will write the name of the attachment in that column else, it will leave the field blank.
Now, my question is: My bot is extracting only first attachment name, but what if the mail has multiple attachments. Right now, I am using “CType(mail.Attachments.FirstOrDefault,Attachment).Name” , this code for getting the name of the first Attachment.
I have also tried “mailMessage.Attachments.Select(function(x) x.Name)”, this code for getting all the Attachment Names but this code is not extracting any value in the variable.
The attachments which are saving in a folder, I can not use Directory.Getfiles(foldername) because the folder can have previous files as well, so if I use this method so with each iteration, it will give the names of unwanted files as well. I want the bot should pick the filenames as the attachments got saved.
I want to get names of the attachments in a variable, whether it is single attachment or multiple attachments. How can I achieve this.
Thanks for your response. I tried the above code and getting “System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Net.Mail.Attachment,System.String]” this as Attachment Name. I don’t know, where I am wrong.
As stated above - the expression will return ienumerable(of string) data type
Looks like you are assigning the result of the expression to a string type variable
You need to create a variable of ienumerable(of string) datatype - see picture in prev post
I am not using the string data type. I am using the variable of IEnumerable type. I have debugged the code, in the variable, I am getting attachment names but as I try to write into excel, I am getting this System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Net.Mail.Attachment,System.String] uipath, in attachment name column.
Please help with this, how can I write the data into excel, Other column names are of type string and this attachment name is of type Enumerable. Thanks
@dimple.khurana
lets assume you want to get a string. give a try on:
myAttachements = String.Join(“,”, mailMessage.Attachments.Select(function(x) x.Name).toArray)