Micro blog
Get notified when a new post is published.
Some times we need to convert Binary to string or string to binary. It can be achieved by following technique. This will help you to convert email attachments in to binary original file format. 1. Convert Binary data / file to string / text protected void Button1_Click(object sender, EventArgs e) { Byte[] arrByte = { 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }; string x = Convert.ToBase64String(arrByte); Response.Write(x); } VB.Net code Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Dim arrByte As [Byte]() = {0, 1, 1, 0, 1, 0, _ 1, 0, 1, 0, 1, 0} Dim x As String = Convert.ToBase64String(arrByte) Response.Write(x) End Sub 2. Convert String to Binary protected void Button1_Click(object sender, EventArgs e) { string str = "This is revenmerchantservices.com domain for ASp.net tips and tricks by Satalaj More"; byte []arr = System.Text.Encoding.ASCII.GetBytes(str); } Vb.Net Binary to string string to binary Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Dim str As String = "This is revenmerchantservices.com domain for ASp.net tips and tricks by Satalaj More" Dim arr As Byte() = System.Text.Encoding.ASCII.GetBytes(str) End Sub 3. Convert binary to Base64 or Binary to string protected void Button1_Click(object sender, EventArgs e) { string str = "This is revenmerchantservices.com domain for ASp.net tips and tricks by Satalaj More"; byte []arr = System.Text.Encoding.ASCII.GetBytes(str); string base64String = Convert.ToBase64String(arr); } Vb.Net code Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Dim str As String = "This is revenmerchantservices.com domain for ASp.net tips and tricks by Satalaj More" Dim arr As Byte() = System.Text.Encoding.ASCII.GetBytes(str) Dim base64String As String = Convert.ToBase64String(arr) End Sub All email attachments are in Base64 string format that is 0-9, A-Z, a-z Let me know your comments about this c# converting.
{
Byte[] arrByte = { 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 };
Response.Write(x);
}
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Dim str As String = "This is revenmerchantservices.com domain for ASp.net tips and tricks by Satalaj More" Dim arr As Byte() = System.Text.Encoding.ASCII.GetBytes(str) Dim base64String As String = Convert.ToBase64String(arr)
End Sub
Trackback from DotNetKicks.com convert binary to bas stringe