Search code examples
formatstring-formattingdata-conversion

What format is this, and how do I convert a byte array into this string format?


I need to edit (change) the image stored in a .resx file that is attached to a Winforms form (actually, it is being loaded into a textbox on an Active Reports (AR) report designer).

The current image is in the xml *.resx file as shown in the code snippet below
(This is just the first few lines of the image in the xml resx file):

<data name="textboxName.ImageBytes" type="System.Byte[], mscorlib">
    <value>&#xD;
iVBORw0KGgoAAAANSUhEUgAADyUAAAImCAYAAABHbbdCAAAAAXNSR0IArs4c6QAAAARnQU1BAACx&#xD;
jwv8YQUAAAAJcEhZcwAAXEUAAFxFAbktYiwAAAAGYktHRAD/AP8A/6C9p5MAAAAHdElNRQffBBsQ&#xD;
Gwt/5sNmAAD/gElEQVR4XuzdO5gX1f0/8HDb5S5yk4vInYBcBJGLNxRFUVEEA4ICKiCgBAEFCUi6&#xD;
VKlSpftVqVKlS5UqVbpUqVKlS5UqVar9zzFj/sg5wF6+3++cM/N6Pc/7+Syo7DlnxmV29nxmfgIA&#xD;
ADAIX3311Znjx4//++WXXx5Zv379yGOPPTYyderUkeofjTrDw8Mjy5cvH3nmmWdGDhw4MHLy5Ml/&#xD;
fP311weqf9ZJFy9e/HVVUmsFAAAAAAAAAAAAAAAAAAB5OnXq1F+fffbZkZkzZ6YaZQeSSZMmjSxb&#xD;
....

This is then loaded into an image on the form (the text box on the AR report designer).

Can someone tell me what format this is? and how to convert the byte array I have generated from the new image (that I need to replace this with), into this format?


Solution

  • This is a base64 format. To convert String in this format in C# use the code below (compite the code in a C#):

    using System;
    using System.Text;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text.RegularExpressions;
    
    
      public class Program
      {
        public static void Main(string[] args)
        {
             //convert string to base64:
        string STR = "my string";
        byte[] VALUE1 = Encoding.ASCII.GetBytes(STR);
        string Valuebase64 = System.Convert.ToBase64String(VALUE1);
        Console.WriteLine(Valuebase64);
    
    
       //convert base64 em String: 
        string Valueinbase64 = "bXkgc3RyaW5n";
        byte[] VALUE2 = System.Convert.FromBase64String(Valueinbase64);     
        string someString = Encoding.ASCII.GetString(VALUE2);       
        Console.WriteLine(someString);
    
            
            }
        }