Invoke Code throwing compiling errors during method declaration

Hi Team, I am having troubles with translating working code in Visual Studio to Invoke code in UiPath.

I am trying to set up a method for checking file name (input) in zip folder (input) and if it’s there, return true, if not - false (output arg)

This is my code:

public bool ReturnZipName (string fileName, string folderName)
{
    using (ZipArchive archive = ZipFile.OpenRead(folderName))
    {
        

        foreach (ZipArchiveEntry entry in archive.Entries)
        {
            if (entry.Name == fileName)
            {
                return true;
            }
                      
        }
        return false;
    }
}

zipFileFound = ReturnZipName(@"FinInvoiceRegisters_20190617193130.csv", @"C:\Users\emea_svc_ibot_bsot01\OneDrive - CBRE, Inc\Documents\UiPath\ES_PMA_APInvoice\Testing\c# test\11_Transfer_20190617_193130.zip");

This is list of my arguments

This is the errors I am getting:

test.xaml: No compiled code to run
error CS1513: } expected At line -1
error CS1519: Invalid token '=' in class, struct, or interface member declaration At line 18
error CS1520: Method must have a return type At line 18
error CS1031: Type expected At line 18
error CS1022: Type or namespace definition, or end-of-file expected At line 20

Can anyone help?

Hi @salladinne ,

We do not really need to define a function or a class to inside Invoke Code to achieve the desired Output as we do in Visual Studio.

Invoke Code Lets us use the Code directly. Although Assembly references would need to be added.

In this case, the System.IO.Compression needs to be Imported through the Imports Panel
image

Use this minimal Code in Invoke Code Activity and Let us know if it Works.

using (ZipArchive archive = ZipFile.OpenRead(folderName))
{
	zipFileFound = false;
        foreach (ZipArchiveEntry entry in archive.Entries)
        {
            if (entry.Name == fileName)
                zipFileFound = true;
                      
        }
 }

fileName and folderName are passed as in arguments and zipFileFound is an out argument.

Also Please Note, the Language Property of Invoke Code Activity should be set to CSharp

Yes, thank you, it worked!
Although it does bother me a bit that there is no way to call a full C# script in UiPath if I do want to make use of methods, classes and more advanced concepts?

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