Compress files to .zip format

It is very helpful.
Is there any way I could add multiple (4-5) files in the parameter of invoke method and create a single zip file for it?

@igul Can you recreate this in Uipath.

 string[] files= Directory.GetFiles(filePath);
        // Create and open a new ZIP file
                    var zip = ZipFile.Open(fileName, ZipArchiveMode.Create);
                    foreach (var file in files)
                        // Add the entry for each file
                        zip.CreateEntryFromFile(file, Path.GetFileName(file), CompressionLevel.Optimal);
                    // Dispose of the object when we are done
1 Like

'ZipArchive' does not have a public instance method named 'CreateEntryFromFile' matching the parameter types, generic type arguments, and generic type constraints supplied to InvokeMethod 'Invoke method'

Interestingly, in the same exact workflow I have a working custom activity that uses this exact call with those params. Checked without CompressionLevel as well (it has a second overload without it), no difference. Restarting etc. doesn’t solve it.

I mean, it’s not an issue for me, since the activity we’ve added is already done and it’s just a couple of lines anyway, but still odd.

1 Like

For some reason I don’t see ZipArchive (Compression.FileSystem) class, I’m using 2016.2 , Windows 2012 R2

You need to manually add the reference to System.IO.Compression.FileSystem in the xaml and restart (see post 5 here).
I’m wondering if it’s not loading it correctly though.

Sometimes I’d wish we could just add references to .dll’s without jumping through endless hoops :frowning:


Good tip. Works for me without Invokemethod as the Retrun type is “ZipArchiveEntry”, but unable to open the Zip file.Am i missing something?

Compress.xaml (9.2 KB)


Please ignore, i forgot to dispose the ZipArchive. Works now.

Compress.xaml (9.2 KB)


while running this code getting unauthorized access exception

Hi @sowmya,

That error is maybe because your zipPath is a folder.

You need to assign it the new zip file to be created(ex: “C:\Users\admin\Documents\”).
Then, assign to the filepath variable the folder path to get the files to be compressed(ex: “C:\Users\admin\Documents”).

It should work without errors after doing this.

1 Like

yes its working fine thank you

I want to attach the zip file and send smtp mail how to do this one?

Hello @sowmya,

You could try to use Send SMTP Mail Message activity:


yes we send mail using SMTP but I want attach all the files presented in zip folder dynamically.
files count may change .:frowning:

Hello @sowmya,
Ok, take a look at this:



excelent work

Can you please share your workflow where it worked for you, as i’m trying to do the same but I’m getting unauthorized exception.

Could you please share your workflow

Hi Manjusha,

The workflow is the one shared by Vinay here, i just assigned the zipPath and filepath variables the corresponding paths. Here it is:
Compress.xaml (9.1 KB)

1 Like

I’m getting compilation error in my xaml file. I imported required namespaces but still no success.


Hi @avi.ngp,

Try System.IO.Path.GetName(file)