I am trying to zip files at a folder location .
I am unable to open application > "Windows explorer "
Also record sequence is not feasible as these files are created during the process workflow .
Eduardo Bernabe Sacahui Diaz September 09, 2016 21:09
Hello and thank you for your help, There is no .Zipfile target type in uipath community I guess V2016.2
You can use powershell to create zip archives. Here is a link to an example script. You need to use the Invoke Powershell Activity. If you at:
param($source,$destination)
at the start of the script you give values to those variables by defining them (with the same name) in the Parameters Proprieties of the Invoke Powershell Activity.
@Eduardo - it isn’t a UiPath issue. The classes needed are in System.IO.Compression.FileSystem.dll (not imported by default, not only in UiPath but VS also). You will need to add a package with reference to it, which might be overkill - Cosmin’s way is much simpler.
If you want to use the .Net classes, there is a trick by the way… Only do this if you know what you’re doing, you might break your file if you mess up the structure
If you open the .xaml in any text editor (Notepad++ is great for that), find assembly reference lines and the one you need, it will load it there.
So for example find this line:
UiPath.Excel
And just after it add (note it’s case sensitive!)
System.IO.Compression.FileSystem
It will then load the assembly you need to use the ZipFile class (and ZipFile extensions are there too, they’re pretty useful).
Using it that way you may load any assembly that is located in you most-up-to-date Reference Assemblies folder (by default: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework[your_version])
Eduardo Bernabe Sacahui Diaz September 14, 2016 15:56 @Cosmin Nicolae … Awesome, thank you i was using a power shell script but a iteration in UiPath to delete the zip files.
@ Andrzej.Kniola WOW! that´s amazing I want to learn more about modifying the xaml in Notepad++ I tried and it works like a charm
Andrzej.Kniola September 14, 2016 17:11
For vast majority of the things you’d want to do using the Studio is quicker and safer. This is just one of the corner cases (~1% maybe) that actually editing the .xaml directly is useful for.
Please note that since the xaml is autogenerated by the Studio, if you modify it directly you might get strange result, corrupt the file or your changes will be reversed next time you modify the workflow in Studio.
You can open particular zip application like 7Zip and after files had generated you can open that application and indicate with absolute path of that you wants to compress. and hit enter then click on ADD and hit enter.
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
zip.Dispose();
Interesting… '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.
Ideas?
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
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\test.zip”).
Then, assign to the filepath variable the folder path to get the files to be compressed(ex: “C:\Users\admin\Documents”).