This article shows how to save document attachments from a Sales Document to a temp file.
Just a sample of some of my code, I am not a trained programmer but this works.