By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

Parsing Base64 encoding

P: n/a
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.
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.

Nov 17 '05 #2

P: n/a
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?
Nov 17 '05 #3

P: n/a
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?
Nov 17 '05 #4

P: n/a
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
LP wrote:
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.

Nov 17 '05 #5

P: n/a
LP
That's easier than I thought, thanks everyone!
"Joshua Flanagan" <jo**@msnews.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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
LP wrote:
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.

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.