Tuesday, September 18, 2007

How to handle a base64binary type


I ran into an issues yesterday on how to handle a base64binary type being returned from a web service. It was a pain to find the answer or maybe my brain wasn't on (very plausible). So, I am going to post it up for some poor soul, even if it is me who is the poor soul again :).

First let me say that a base64binary type is basically just a byte array base64 encoded.

In my example I am returning this base64binary type as a download but there are a few different ways to use it.


byte[] attachment = new byte[15]; // pretend this is the base64binary :)

Response.BinaryWrite(attachment);


Way too easy, just took me awhile to find. Another way you can do screw around with the values is doing something like.


byte[] attachment = new byte[15]; // pretend this is the base64binary value

for(int i = 0; i < attachment.Length; i++) {
Response.Write(Convert.ToChar(attachment[i])) ;
}


This is a little bit more code and little harder to read but works as well.

I am sure there are like 10 other ways to screw around with these values but both of these worked, so, hopefully this will help someone else.

0 Comments:

Post a Comment

<< Home