I’ve a couple of files to attach in a mail and to simplify the life of receivent i want to zip in a unique file. All works fine, but outlook can’t attach a file > of 20/25 MB.
To workaorund this, i’ve think to do a condition like this:
For each item in Directory.GetFiles("PDF");
add to collection ListBatch (list of String)
assign system.IO.fileinfo filesize = New System.IO.FileInfo(item)
Math.Round(filesize.SizeInKB)
add to collection SumBatch (list of int32)
assign Int32 Sum = SumBatch.Sum
If Sum > 20 MB then
Zip ListBatch —> (“C:\user\nameoflist.zip”)
Clear collection
Now the issue is: how i can transform zip name in a variable? To change the name of the zip before the new one overwrite the old one?
And how can i add the value of FileSize in kb to a SumBatch collection?
You can create this List(of Strings).
Create int_Size = 0
After that place this for each file in array:
Inside check size of the file in kb and assign to int_FileSize
Int_Size = int_Size+int_FileSize
If int_Size < 20000
Then add path to collection.
Else:
Str_fileZip = "zip_"+now.toString("yyyyMMdd_HHmmss")+".zip"
Archive this collection to zip.
Clear collection ( new list(of String))
Int_Size = int_FileSize
add path to cleared collection
It will add to collection until is less than 20mb.
If there is more it creates zip with unique name, clear collection and add a new file for next package.