Prakash Mani
Prakash Mani

Reputation: 115

Include binary data in XML file

We need to upload the attachments(for ex. word document) in xml file. Is there any way to attach this? Any sample code using c# will be appreciated.

Upvotes: 3

Views: 4510

Answers (2)

jammus
jammus

Reputation: 2550

An alternative is to store a uri to the resource instead of attempting to include it within the XML.

<?xml version="1.0"?>
<item>
    <attachment type="word">http://path.to/document</attachment>
</item>

The client is going to have to do some work to either unencode or fetch the attachment anyway so doing it this way could save a lot of pain.

Upvotes: 0

GreyCloud
GreyCloud

Reputation: 3100

Have a look at this article: http://www.codeproject.com/KB/XML/xml_serializationasp.aspx it describes saving bmp images into and out of xml by converting them to byte arrays. I suspect a similar method would work for other files.

Upvotes: 3

Related Questions