Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert image into xml file using c#

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

like image 692
lilly1 Avatar asked Jan 23 '11 21:01

lilly1


People also ask

Can you store an image in XML?

XML files contain data in the form of text. Any data can be stored in and retrieved from an XML file as long as you can convert the data to text before writing to the XML file and then convert the text from the XML file into the correct data type when reading it back.

How do I view an XML image?

Just about every browser can open an XML file. In Chrome, just open a new tab and drag the XML file over. Alternatively, right click on the XML file and hover over "Open with" then click "Chrome". When you do, the file will open in a new tab.


1 Answers

  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!

like image 146
OJ. Avatar answered Sep 24 '22 09:09

OJ.