# Execute custom code

Source: [https://docs.virtosoftware.com/docs/virto-workflow-automation-web-part/virto-sharepoint-workflow-activities-kit-sharepoint-2010-workflow-platform/code-activities/execute-custom-code/](https://docs.virtosoftware.com/docs/virto-workflow-automation-web-part/virto-sharepoint-workflow-activities-kit-sharepoint-2010-workflow-platform/code-activities/execute-custom-code/)
Product: Virto Workflow Automation Web Part
Updated: 2026-08-12


This activity enables the execution of custom C# or VB.NET code from within SharePoint Designer Workflows.

![Execute custom code workflow activity running C# or VB.NET code inside SharePoint Designer Workflows](https://img-docs.virtosoftware.com/wp-content/uploads/2024/10/execute_custom_code_1.png)

You can use this activity to invoke custom C# or VB.NET code in SharePoint Designer without needing to create complex Visual Studio workflows. The activity follows a script-like approach, so there’s no need to define namespaces, classes, or method names.

**Note**: The code should include the `using` (imports) section and code lines without method (Sub procedure) declarations.

**Note**: This activity uses .NET 3.5 to compile custom code, so all .NET 3.5 features are available within the code.

The following example reads XML from `parameter1`, selects a node by XPath from `parameter2`, and stores the string result in the output variable.

**Example Code**  
*C#:*

![C# example code that reads XML and selects a node by XPath in the Execute custom code activity](https://img-docs.virtosoftware.com/wp-content/uploads/2024/10/execute_custom_code_2.png)

**[VB.NET]**

![VB.NET example code for reading XML and selecting a node by XPath in the Execute custom code activity](https://img-docs.virtosoftware.com/wp-content/uploads/2024/10/execute_custom_code_3.png)

You should use the `Context` variable to access incoming parameters and return results from your custom code.

You can embed Workflow Lookup variables into the code. At runtime, all lookup variables are replaced with text, so please ensure the generated syntax remains valid.

For example, the following code may not execute correctly:

```
string userFirstName = [%Variable: firstName%];
```

This could result in:

```
string userFirstName = Frank;
```

To solve this, add quotes around the variable as follows:

```
string userFirstName = "[%Variable: firstName%]";
```

This will result in the following syntactically correct code:

```
string userFirstName = "Frank";
```

The `Context` variable includes several properties for use in your code:

## **Properties**


| Property | Type | Description |
|---|---|---|
| WorkflowContext | WorkflowContext | Gets the workflow context. |
| CurrentList | SPList | Gets the current SPList object. |
| CurrentListItem | SPListItem | Gets the current SPListItem object |
| InParameter1 | Object | Gets the incoming parameter #1 |
| InParameter2 | Object | Gets the incoming parameter #2 |
| CurrentActivity | Activity | Get the current activity. |
| WorkflowInstanceId | Guid | Gets the Guid associated with the workflow instance. |
| ActivationProperties | SPWorkflowActivationProperties | Represents the initial properties of the workflow instance as it starts. |
| Result | Object | Gets or sets the output result. |


The following Assembly References are available by default:

- `Virto.Sharepoint.Activities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7b70ddd211dc63c8`
- `System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089`
- `System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089`
- `System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089`
- `mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089`
- `System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089`
- `System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35`
- `Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c`
- `Microsoft.SharePoint.Workflows, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c`
- `Microsoft.SharePoint.WorkflowActions, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c`

***Note**: The assembly should be installed in the Global Assembly Cache (GAC).*

You can add or remove references to custom assemblies. The string format must follow the full assembly name.

***Note**: A reference to the `Virto.Sharepoint.Activities` assembly is required.*

## **SharePoint Workflow Designer Phrase**

Execute **this code** written in **C#**, passing incoming parameters **parameter1** and **parameter2**, use referenced assemblies **Virto.Sharepoint.Activities** and store result in **result**.

**Parameters**


| Parameter | Description |
|---|---|
| this code | C# or VB.NET code |
| C# | Type of code: C# or VB.NET. |
| parameter1 | **Optional**. The incoming parameter #1. Default value is null. |
| parameter2 | **Optional.** The incoming parameter #2. Default value is null. |
| Virto.Sharepoint.Activities | **Optional**. List of referenced assemblies in the full assembly name format, e.g., System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. |

