Parsing Base64 encoding

L

LP

A web service returns base64 encoded data. The goal is to parse it and store
it into binary file with .dat extension. This file is then will be used by a
custom program to produce diagrams. As far as I know base64 data is not any
known graphic format, from what I understand it's just encoded stream of
bytes. Which I need to write to .dat file. Where to start? any links or
suggestions?

Thank you.
 
B

Bruce Wood

Have you tried this?

Declare the element in question in the XML schema for the Web Service
as being "base64Binary".

Load the results of the Web Service call into a DataSet. The resulting
DataColumn should have a type of Byte and the byte array it contains
should be the binary version of the base 64 encoding in the XML.

Failing that, I did write my own base64 encoding class that I could
pass along.
 
L

laimis

If you care just saving the bytes into the file, use FileStream class
provided by .net. It provides a Write method that accepts a byte array
as a parameter (byte array would be your base64 data).

If you need to decode base64 encoded data, simple use
Convert.ToBase64String() method which is also provided by the framework.
base64 is nothing special, just bytes which values are limited by the
set of characters that belong to base64 encoding.

Does that answer your question?
 
L

laimis

If you care just saving the bytes into the file, use FileStream class
provided by .net. It provides a Write method that accepts a byte array
as a parameter (byte array would be your base64 data).

If you need to decode base64 encoded data, simple use
Convert.ToBase64String() method which is also provided by the framework.
base64 is nothing special, just bytes which values are limited by the
set of characters that belong to base64 encoding.

Does that answer your question?
 
J

Joshua Flanagan

As the other posters have hinted at, you just need to use the Convert
class and a way to write the data to disk (FileStream works nicely).

Assuming your base64 data is in a string named receivedBase64string, and
you want to write it to the file c:\received.data

using System.IO;


byte[] rawData = Convert.FromBase64String(receivedBase64string);
using (FileStream fs = new FileStream(
@"c:\received.dat",
FileMode.Create))) {
fs.Write(rawData, 0, rawData.Length);
}


Joshua Flanagan
http://flimflan.com/blog
 
L

LP

That's easier than I thought, thanks everyone!


Joshua Flanagan said:
As the other posters have hinted at, you just need to use the Convert
class and a way to write the data to disk (FileStream works nicely).

Assuming your base64 data is in a string named receivedBase64string, and
you want to write it to the file c:\received.data

using System.IO;


byte[] rawData = Convert.FromBase64String(receivedBase64string);
using (FileStream fs = new FileStream(
@"c:\received.dat",
FileMode.Create))) {
fs.Write(rawData, 0, rawData.Length);
}


Joshua Flanagan
http://flimflan.com/blog

A web service returns base64 encoded data. The goal is to parse it and store
it into binary file with .dat extension. This file is then will be used by a
custom program to produce diagrams. As far as I know base64 data is not any
known graphic format, from what I understand it's just encoded stream of
bytes. Which I need to write to .dat file. Where to start? any links or
suggestions?

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top