Skip to content

Instantly share code, notes, and snippets.

@tomaustin700
Created April 20, 2018 10:23
Show Gist options
  • Save tomaustin700/1eb5a98ec4c866393e0a31ea042f1b39 to your computer and use it in GitHub Desktop.
Save tomaustin700/1eb5a98ec4c866393e0a31ea042f1b39 to your computer and use it in GitHub Desktop.
Converts SQL varbinary image into C# Byte[]
string stringFromSQL = "0x6100730064006600";
List<byte> byteList = new List<byte>();
string hexPart = stringFromSQL.Substring(2);
for (int i = 0; i < hexPart.Length / 2; i++)
{
string hexNumber = hexPart.Substring(i * 2, 2);
byteList.Add((byte)Convert.ToInt32(hexNumber, 16));
}
byte [] original = byteList.ToArray();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment