Hi All
I setup a (SharePoint) document type in Dynamics. When user create new Purchase Order, user will add file(s) to attachments (SharePoint).
New we need a customization, to send email to vendor with attachment(s). So, we need code to download file(s) from SP attachment and send email to Vendor.
However, when I use below code
"url = DocumentManagement::getAttachmentPublicUrl(docuRef)"
The URL is too long because it is URL+token. when I use this URL, I can navigate to.
new Browser().navigate(url, DocuSharedParameters::isOpenAttachmentsInNewWindowEnabled(), false); // success
but I will get error in
_client.DownloadFile(url,docuValue.FileName + '.' + docuValue.FileType); // Failed because string is to long.
I also tried this one
JfileStream = DocumentManagement::getAttachmentStream(docuRef);
but when I set JfileStream in email parameters, I will get error again.
messageBuilder.addAttachment(JfileStream, docuValue.FileName + '.' + docuValue.FileType);
Does anyone has idea about how to download file from SP (attachment) and send with email?
Best Regards,
JustZM
Yes, of course that getAttachmentAsContainer() uses getAttachmentStream(). I didn't told you to use getAttachmentAsContainer(), I told you to copy the result of getAttachmentStream() to a MemoryStream and that you can see such an example of such code in getAttachmentAsContainer(). Please try my actual suggestion.
Your code makes no sense to me. It seems that you're creating a new memory stream for every byte, and throw away all except of the last one. Then you attach just the last byte as the file, which obviously isn't the full content of the file.
Hi Martin
Thank you for your reply. I just tried getAttachmentAsContainer(), and I can receive email with attachment now. However, getAttachmentAsContainer also use getAttachmentStream function.
I use below function to prepare Stream type
when I receive file, and try to open it. I got below error.
Please advise.
Best Regards,
JustZM
A solution for the message builder would be copying the contents to a memory stream and using this stream instead. You can see an example in DocumentManagement::getAttachmentAsContainer().
André Arnaud de Cal...
291,969
Super User 2025 Season 1
Martin Dráb
230,842
Most Valuable Professional
nmaenpaa
101,156