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
Tags:
9/1/2009 3:13:56 PM #
Trackback from DotNetKicks.com convert binary to bas stringe
DotNetKicks.com
3/23/2010 7:38:52 AM #
There is obviously a lot to know about this. I think you made some good points in Features also.
instant payday loans
3/23/2010 12:27:56 PM #
Hey very nice blog!! Man .. Beautiful .. Amazing .. I will bookmark your blog and take the feeds also...
payday cash advance
3/24/2010 6:40:51 AM #
Found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later .. Big thanks for the useful info i found on c# binary to string.
genital wart removal
4/15/2010 1:42:15 AM #
Very interesting post - Might be old news, but it was news to me.
us
4/16/2010 9:07:58 PM #
Can you Please provide the code sample of embedding base64 into mail body. I tried http://forums.asp.net/p/1466611/3385668.aspx approach not able to render the image in the mail body. Thanks, Srikanth
srikanth
4/23/2010 11:10:32 PM #
Fine information, many thanks to the author. It is puzzling to me now, but in general, the usefulness and significance is overwhelming. Very much thanks again and good luck!
bağkur sorgulama
Get notified when a new post is published.