Insert image into xml file using c#

lilly1 picture lilly1 · Jan 23, 2011 · Viewed 14k times · Source

I've looked everywhere for the answer to this question but cant find anything so hoping you guys can help me on here.

Basically I want to insert an image into an element in xml document that i have using c#

I understand i have to turn it into bytes but im unsure of how to do this and then insert it into the correct element...

please help as i am a newbie

Answer

OJ. picture OJ. · Jan 23, 2011
  1. Read all the bytes into memory using File.ReadAllBytes().
  2. Convert the bytes to a Base64 string using Convert.ToBase64String().
  3. Write the Base64 Encoded string to your element content.

Doneski!