How do I convert a base64 encoded bytearray?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

I have a webservice which queries a table in SQLServer. The table has a
column, "Text", which is of datatype "image". When invoking the webmethod it
returns dataset with the table included. The column is returned as a
base64binary as can be seen in the declaration excerpt below:

<xs:element name="text" type="xs:base64Binary" minOccurs="0" />

When I call the webservice and loops through the rows I see that the column
"text" is represented as a bytearray as well. What I'd like to do is to
convert this bytearray into an "ordinary" string. Please note that it must
work in a .Net Compact Framework environment. I've tried a number of
approaches but none has worked so I feel a little bit "lost in binary space".

Hope you can help me!
/Peter
 
I forgot to mention that the data represented in the base64 bytearray is text
so what I want to do is to convert the text which is encoded in the base64
bytearray into a string.

Thanks again!
/Peter
 
Hello,
You can use System.Text.Encoding.ASCII.GetString method to get string a
ASCII encoded string. see System.Text.Encoding class in MSDN for more
details.

HTH. Cheers.
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net
 
Hi Maqsood!

Thanks for your suggestion but I've tried that approach earlier with no
avail. Let me give you some more information:

When calling the webservice I get the following response (most of the
response removed for clarity):
<text>H4sIAAAAAAAAAM1Y23LbOBJ9nlTlH1B........</text>

As you can see the content of the base64 encoded bytestream contains a
base64 representation of the actual text. When I use your suggestion I get a
string alright but it is impossible to read. I think the problem is that the
..GetString method doesn't work with base64 encoded byte arrays.

Thanks again!
/Peter
 
Back
Top