I have more than 30 files with total size 45MB, i need to send them out by mails, but the attachments will be limited to 10MB every time, that means i need to send 5 times.
Now I am reading all the files to a array using Directory.GetFiles(FilePath, “.”,SearchOption.AllDirectories), but how to separate this array to 5 arrays and make sure each total size smaller than 10MB ? and then I can send it out by mail with each files array.
thanks so much
Michael
I have attached the workflow which will give the file size in MB
After measuring Each file size Just check within If Activity as fileSizeInMB <= 10
If Yes then create the New List & repeat the loop and add the next file in New List which will consists of the files having size less than 10MB along with that add the file Size also till it gets 10MB to the same variable fileSizeInMB or you can also have any new variable
If No means if it is greater than 10 MB then within else you will mail the files of the new List created and move those files to another folder just for convenience that one by one as per the files are mailed they are moved to another folder. And after mailing just make the new List Empty and then add the current loop file to the new list and assign variable fileSizeInMB = currentLoopFileSize
thanks so much for your solution.
but the big challenge is when we do the for each, perhaps in current loop the total size is 7 MB but next loop it will be more than 10MB .
so it is hard to know in which loop we should send the files out.
Loop through all files.
Use an if-statement to check if the combined size of the files in the list/collection and the current file is more than 10 mb.
If it is send all the files EXCEPT the current one. Empty the list and add the current file to the list/collection.
If it is not more than 10 mb, add the current file to the list/collection.
When you are at your last file, remember to send the list/collection of files. It might contain only the last file and it might contain more files.