In order to efficiently handle the creation (and extraction) of large attachments with SPS, we're interested in the IAttachmentFile's CopyTo( ) method, which accepts a Stream.
1) I'm assuming I can build a class which derives from Stream and is capable of providing the next set of bytes from my Source whenever the SDK calls Read on the given Stream within the CopyTo's implementation. Is that a safe assumption?
2) As the bytes are streamed to the IAttachmentFile via the CopyTo( ) method, are they accumulating in the client's memory footprint, or is the SDK sending them on to the server for appending to the corresponding Blob storage ? Put another way, if we use this operation, and then the user closes the open Order without saving, what happens to the new attachment ? Kept or discarded?
- Use SetStream(Stream stream, string extension) and pass in an object that implements the Stream functionality. (As you correctly stated.)
- Or use SetStream(string path) and pass the filesystem location of a file.
By the way, CopyTo() would be used if you wanted to read a copy of the attachment file and write it to another destination - not if you wanted to provide content to be written to an attachment file. (I find the method names confusing too.)