How to store string value to binary variable(Varbinary datatype)

I want to store a string variable value into binary variable (Varbinary datatype).

I am using UiPath.system.activities= 21.10.3
UiPath.uiautomation.activities= 22.4.4
Studio version 2020.10.3

I can’t downgrade the package version.

Hi @BNK

Have you tried like this?

  1. Create a binary variable, let’s say binaryValue, of type Byte[] to store the binary representation.
Assign activity: stringValue = "Hello World!"

Assign activity: binaryValue = System.Text.Encoding.ASCII.GetBytes(stringValue)

Regards
Gokul

Hi @BNK

Have you tried like this for Varbinary datatype?

  1. Create a variable, let’s say binaryValue, of type System.Data.SqlTypes.SqlBytes.

  2. Convert the string value to a byte array using the System.Text.Encoding.Default.GetBytes() method.

Assign activity: stringValue = "Hello World!"

Assign activity: binaryValue = New System.Data.SqlTypes.SqlBytes(System.Text.Encoding.Default.GetBytes(stringValue))

Getting this error