views:

978

answers:

2

Hi, I am saving some small images to Xml as a Byte[] via the following XElement construct..

XElement xe = new XElement("Images",
            from c in qry
            select new XElement("Image", new XAttribute("Date", c.Date),
              new XElement("Data", c.Bytes)));

the Bytes property is a Byte[], looking at the resulting element the contents of the array appear to be saved just peachy.

My problem is I can't seem to read this back simply. What is the best way to retrieve this element? Typecasting to a Byte[] appears to be not allowed, am I really going to have to read this as a string? Figure out what encoding to use and convert? Seems to me that given that XElement understood how to write the array, it should be able to read it as well.

+2  A: 

I would think about Base64 encoding the byte array. It should be fairly easy to encode/decode this from/to a byte array.

tvanfosson
Yep, you are right, much easier. Thanks.
Tim Jarvis
A: 

This was very helpful, thank you. For a coding sample see:

http://www.nowan.hu/main.aspx?content=9cff1555-26ca-4e6a-910b-6a73463e22b2

Josh Loeb