web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Business Central forum
Under review by Community Managers

Under review

Thank you for your post! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Sending Excel as Attached File Corrupts the file

Posted on by 2
Hi everyone!
 
I am sending document attachment files with Sales Invoices as PDFs via e-mail.
If the attached files are PDFs everything works fine, but if the file is an EXCEL, the reciever gets that file corrupted.

The code is pretty simple and straightforward, have you seen/experienced anything similar?
//attachements
                DocAtt.SetRange(/Table ID/, 112);
                DocAtt.SetRange(/No./, SIH2Print./No./);
                if DocAtt.FindSet() then
                    repeat
                        if DocAtt./Document Reference ID/.HasValue then begin
                            TempBlob.CreateOutStream(DocOutstr);
                            DocAtt./Document Reference ID/.ExportStream(DocOutstr);
                            TempBlob.CreateInStream(DocInstream);
                            FileName := DocAtt./File Name/ + '.' + DocAtt./File Extension/;
                            case UpperCase(DocAtt./File Extension/) of
                                'PDF':
                                    ContentType := pdfLabel;
                                'XLSX':
                                    contentType := excelLabel;//'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
                            end;
                            EmailMessage.AddAttachment(FileName, contentType, DocInstream);
                        end;
                    until DocAtt.Next() = 0;
                sent := Email.Send(EmailMessage);
Any help is apreciated.
 
Thanks!

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans