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

How to convert DataTable to Base64?

P: n/a
I am looking for an example of how to save a DataTable into Base64 and
vice-versa. I tried using Convert.ToBase64String(), but it says that it
cannot convert DataTable to byte[]. Any help or pointing would be
appreciated.

Thanks

Rod

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Rodusa,

The easiest way to do this would be to get the contents of the DataTable
in XML, then convert that to a byte array, then convert that to the base 64
string. To get the XML, use the WriteXml method on the DataTable (this
might be new for 2.0, I can't remember, if so, then use the WriteXml method
on the DataSet that the DataTable is in). Once you have the XML, you can
convert to a byte array using one of the Encoding classes (use
UnicodeEncoding if you don't know the encodings of the XML, or another more
appropriate one if you know the encoding will always be the same). Once you
have the bytes from the encoding, getting the base 64 string is easy.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rodusa" <rc**********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I am looking for an example of how to save a DataTable into Base64 and
vice-versa. I tried using Convert.ToBase64String(), but it says that it
cannot convert DataTable to byte[]. Any help or pointing would be
appreciated.

Thanks

Rod

Nov 17 '05 #2

P: n/a
Nicholas,

Thank you. I will try that.

Rod

Nov 17 '05 #3

P: n/a
Note that once it's in XML format, it's probably already in a form
sufficent for what you were planning to use the Base64 for (most of the
troublsome codes would have been converted to characters < 0x80)

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"Rodusa" <rc**********@yahoo.com> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com...
Nicholas,

Thank you. I will try that.

Rod

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.