3

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.

3
  • 1
    This question doesn't make any sense. What would an XML file with an attachment look like? Once you can show me such an XML file, we can talk about how to create one. Commented Dec 23, 2010 at 20:12
  • Upload from where to where? In what XML file? Can you elaborate your question? Commented Dec 23, 2010 at 20:13
  • My main requirement is sharing the information/data across the platform/application without using web services (becuase the receiver application wont support web service) Commented Dec 23, 2010 at 20:31

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is not a great answer, because base 64 is so inefficient in terms of both time and space. SOAP supports binary formats such as DIME, which would work better here.
0

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.

2 Comments

The statement is: "in xml file", not outside it.
True, I was just offering an alternative. I've been down the path of trying to include binary data in xml before and it turned out not to be the optimal solution in that case. Maybe op hadn't considered that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.