Get multiple Files in Folder and send it In Email

Hi I just wanted to get multiple Files from a Folder and Store it in a string variable,

image

The problem is, after I get and Stored the list of String in One String using this strText = String.Join(“,”,strFilearr.toarray) It gives me the full path of Each Files, the reason why it throws some error.

I just wanted all files in one Folder and attached it in the email

image

Thank you, Please help me

Original thread.

@Vincent_Nuestro - To get the filename alone…please try this code

String.join(",",New System.IO.DirectoryInfo(YourFolderPath).GetFiles().Select(Function(file) file.Name).ToArray())

or

String.join(",",Directory.GetFiles(YourFolderPath).Select(function(x) new fileinfo(x).Name).ToArray())

Hope this helps.

Hi , What do you think is the problem? I used both of your code, and it gives me all the file name inside the folder. But im still getting error.

@Vincent_Nuestro - please show us screenshot of the email activity ??

Basically, you just have to pass the array in the collection arguments…

@prasath17
Here is my Invoke workflow activity
image

Here is the arguments of filepath
image

testPathAttach = String.join(“,”,Directory.GetFiles(MyFolderPath).Select(function(x) new fileinfo(x).Name).ToArray())

Arguments inside Invoke Code

@Vincent_Nuestro - Sorry I haven’t tried invoke code method to send email…

Hi @Vincent_Nuestro ,

mail.Attachments.Add() → Takes a File Path. Hence if you want to add multiple files as attachment then you need the input argument to be (An Array of String) String[] and you will have to loop over this String[] and call the mail.Attachments.Add() method within the loop.

Hope that helps !

Thanks & Regards,
Nithin

May be you can use this
ArrayString = System.IO.Directory.GetFiles(Directory Path)
Then, put the ArrayString into the Mail Activity (AttachmentsCollection)

1 Like

Hi, should be something like this?

image

@Vincent_Nuestro - For Send Outlook mail message activity, this is how I configured…Here StrSummaryFiles is StrArray of all the summary files with simple directory.getfiles…

image

Hi I already tried this method but it Didn’t work for me bcoz, I have email template in outlook (.oft file) and I must replace some data like <nickname, startdate, etc…> that the reason why i need to use invoke code activity. the data came from excel file and replace it in the email template.

Example of data needs to replace.
image
image

and im working on attachment of files im still getting errors :frowning:

Hi @Vincent_Nuestro,

First perform the following to get the Files to be Attached in a String[]:
in_Attachments=Directory.GetFiles("<FolderPath>")

On Invoked Code Arguments change the AttachedFile Type from String to String[]. Next inside the code you can call a for each loop to loop through the String Array AttachedFile and within the loop add one file at a time to the mail object as follows:

image

Hope that helps !

Thanks & Regards,
Nithin

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.