473,660 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to convert DataTable to Base64?

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

Thanks

Rod

Nov 17 '05 #1
3 5675
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.co m

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

Thanks

Rod

Nov 17 '05 #2
Nicholas,

Thank you. I will try that.

Rod

Nov 17 '05 #3
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**********@y ahoo.com> wrote in message
news:11******** ************@g1 4g2000cwa.googl egroups.com...
Nicholas,

Thank you. I will try that.

Rod

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
17130
by: marcelo szwarc via .NET 247 | last post by:
I already broke my head, searched everywhere. PLEASE I NEED YOUR HELP! Do you know how can I convert an image file( like a gif or jpeg ) to a Base64 string? I need to use it to send embedded image files through email. I only need this to finish my app. Thank you!!! -------------------------------- From: marcelo szwarc ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/)
4
7943
by: Albert Jan | last post by:
Hi, I have text from mime email messages with different encoding that I want to convert to utf-8, but I'm relatively new on encoding problems. I use the following code, but this doesn't seem to work (the in and output remains the same): string x=toUTF8("=?GB2312?B?s8q5q8u+vq3A7aGissbO8bK/w8W1xNK7t+LQxQ==?=","GB2312");
2
5629
by: VenuGopal | last post by:
Hi Everyone, in my application i am interacting to a known server. i send a request and get a response from the server. i am using XML and HTTP here. part of the job is that the XYZ server is sending a image in the Ascii format using XML. ASCII is not useful for me to display the image. i need to convert it to BASE64 format... so i can go ahead and view the image. How do u convert ASCII to Base64 in C#.
1
21152
by: James dean | last post by:
The following code is the current method i have for converting an image to Base64.Is this the most efficient way to convert an image to base64 or are there others. The Image class's Save method is slow here and i am wondering if i can do it some other way to make it faster.....Any ideas public string ImageToBase64String(Image imageData ImageFormat format) { string base64; MemoryStream memory = new MemoryStream(); imageData.Save(memory,...
3
18684
by: ablyplus | last post by:
Hi, I have conversion like following: string Source; // convert from Base64 to binary byte bytIn = System.Convert.FromBase64String(Source); Everything works fine. Problem is in Source Data.
4
5530
by: Russell Warren | last post by:
I've got a case where I want to convert binary blocks of data (various ctypes objects) to base64 strings. The conversion calls in the base64 module expect strings as input, so right now I'm converting the binary blocks to strings first, then converting the resulting string to base64. This seems highly inefficient and I'd like to just go straight from binary to a base64 string. Here is the conversion we're using from object to...
29
5074
by: Harlin Seritt | last post by:
Hi... I would like to take a string like 'supercalifragilisticexpialidocius' and write it to a file in binary forms -- this way a user cannot read the string in case they were try to open in something like ascii text editor. I'd also like to be able to read the binary formed data back into string format so that it shows the original value. Is there any way to do this in Python? Thanks!
1
6073
by: pnbaocuong | last post by:
Dear All When I try to use convert function of MS sql server like this: String sql = " (employee_id = '" + employee_id + "') and ((convert(VARCHAR,w_date,103) = '" + w_date + "'))"; PAYROLLDataSet.WORKINGTIMESRow workingtime_row = (PAYROLLDataSet.WORKINGTIMESRow)pAYROLLDataSet.WORKINGTIMES.Select(sql); Whe I run, it rais bellow exception:
6
5260
by: Bob Altman | last post by:
Hi all, I'm looking for the fastest way to convert an array of bytes to String. I also need to convert a String back to its original Byte() representation. Convert.ToBase64String and Convert.FromBase64String seem like the closest thing I can find to what I'm looking for baked into the base class library. Can anyone suggest a better way to do this? TIA - Bob
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.