Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I want to embed and retrive files such as pdf, word doc, jpg or png images In InnerText of XML nodes.
How can I change my files to String to insert into xml nodes?
please help me
Posted
Updated 16-Aug-11 23:13pm
v3
Comments
Mycroft Holmes 17-Aug-11 5:09am    
Can you clarify - are you hoping to turn image files into text?
moslemB 17-Aug-11 5:10am    
yes
images file and word documnets and pdf file
Simon Bang Terkildsen 17-Aug-11 5:15am    
Seems like an abuse of xml to me, xml is supposed to be human readable.
Do you mind me asking why you would want to do this? I'm sure there is a better solution.

There are two possibilities:

  1. Convert your file into a hexadecimal encoded byte string, and use that
  2. Insert the file location as a string possibly as a CDATA item

Option 2 would be more appropriate as it would reduce the amount of data in the XML. However, it may be that XML is not the best solution to your problem.
 
Share this answer
 
if your purpose is to save multiple files together, making it easy to move or access related files, then I personally would use zip. If this has any interrest have a look at this article
C# Zip Files and/or Folders[^]
 
Share this answer
 
the best way is read all bytes of file and convert that array of byts to Base64 and insert result text into innertext.

byte[] bytes = System.IO.File.ReadAllBytes(filename);
String str = Convert.ToBase64String(bytes);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900