问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/4522119/include-binary-data-in-xml-file