The InvokeMethod activity is another way to implement a code which is outside of the standard built-in activities. You can use this activity to invoke a method of a class.
The class does not need to be part of the workflow or use any of the workflow base classes. The InvokeMethod calls a public method of a specified object or type.


InvokeMethod Properties:
- MethodName: Assign the method name to this property.
- TargetObject: When we want to invoke non-static methods, we need first to create an object that contains the method to execute.
- TargetType: When we want to invoke static methods, we specify the type that contains the static method to execute.
- GenericTypeArguments: When we want to invoke a generic method, we specify generic types in this collection.
- Parameters: The parameter collection of the method to be invoked.
- Result: The return value of the method execution.
Let’s try demonstrating it with few examples:
Example – 1
Suppose we have a scenario in which we have to merge two datatables, let’s see how to do it …
Step 1:
Drag “Build Data Table” activity into the designer panel and build a datatable with some sample data and let’s call it DT1.

Step 2:
Drag another “Build Data Table” activity into the designer panel and build a datatable with some sample data and let’s call it DT2.

Step 3:
Drag another “Invoke Method” activity into the designer panel and pass the required parameters as shown in the below figure and display it in a message box.

Step 4:
Here is the output 🙂

Click here to download the Source Code…
Example – 1
Suppose the task is to unzip a file using InvokeMethod activity. The task which rather seems little difficult and would need some understanding of code can be done easily using InvokeMethod.
Step 1:
Drag “Assign” activity into the designer panel and assign the .zip file path to it.

Step 2:
Drag “Assign” activity into the designer panel and assign the directory path to which the extracted files should be moved to..

Step 3:
Drag “Invoke Method” activity into the designer panel and pass the required parameters as shown below

It will invoke a method (ExtractToDirectory) of class System.IO.Compression.ZipFile. The parameters required by the methods are:
- zipPath <String>
The path to the archive that is to be extracted.
- extractPath <String>
The path to the directory in which to place the extracted files, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory.
Step 4:
Here is the output 🙂

Click here to download the Source Code…
Hope it has helped you…
Connect with Anmol Yadav on LinkedIn 🙂