Click here to Skip to main content
15,030,781 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi Experts,

I want to encode byte array to string in android 4.0 application,
and decode this string to byte array in C# .Net Web service.

I only want a function for encode byte array in android 4.0
and decode this string in .Net Web Service.

Any one can help me...?
Thanks in advance

Hello friend,

you can use this two methods for converting bytes to string encoding with base64 and visa versa

internal byte[] StringToBytes(string streamString)
     return Convert.FromBase64String(streamString);

internal string BytesToString(byte[] stream)
    return Convert.ToBase64String(stream);

for android please review this links...[^][^][^]
Mr. Mahesh Patel 26-Feb-13 7:51am
Are u sure that BytesToString is working fine in android...?
Tejas Vaishnav 26-Feb-13 7:57am
its for C# only for your webservice, you need to find android base64bit converter on
Just in case google isn't working for you I found this by doing a simple search:
android.util.Base64 extends java.lang.Object[^]



— Manfred
Mr. Mahesh Patel 26-Feb-13 7:52am
I have already use this both function but it is giving error of "Invalid image or unsupported image format" while i decode string in byte array and use it as image at .Net Side.
Manfred Rudolf Bihy 26-Feb-13 8:11am
Then why didn't you include that information in your question.
Your are wasting ours and your time as well.
Please read the forum posting guidelines.
CPallini 26-Feb-13 8:33am
If you have such problems you have to debug: see how Android side encodes and how the .NET side decodes. Base64 is not rocket science.
BTW could even be that .NET actually doesn't support the image format.
Manfred Rudolf Bihy 26-Feb-13 8:34am
Just a thought: Why don't you start with somthing where you have a little more control. Fill a byte array with a sequence of bytes from 0 to 111. The convert that on Android and send it to .NET where you will decode it. You can then verify if the array contains the same sequence.
I suspect you may be having a problem with the image conversuin.

Please try to verify the basics operations first, before you build something more complex with it. It will help you pin down where your problems really are.


Mr. Mahesh Patel 26-Feb-13 8:28am
I have try lots of links, How can I post all the things,
You should have to give answer with confident and conformation.
Please don't give answer if you are not 100% sure.
Because I know googling very well...
Thanks for your time, I dont need more times from you.
CPallini 26-Feb-13 8:31am
I'm confident he is confident.
Manfred Rudolf Bihy 26-Feb-13 8:38am
Please don't be abusive, you are the one asking the questions, not I. Read my comment where I'm guiding you on how to go about finding where you problems really are. And you are not supposed post everything you tried, but that doesn't mean not giving anything about what you did at all is any better. Start using your brain, and quit being obnoxious. I'll consider reporting the abuse. Regards, <dd>— Manfred</dd>
CPallini 26-Feb-13 8:31am
My 5.
Manfred Rudolf Bihy 26-Feb-13 8:38am
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900