Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Sending SSRS report as encrypted pdf document via email not working in production environment in D365 F&O.

Posted on by 27,832 Super User 2024 Season 1

We are trying to send an SSRS report as encrypted pdf document via email. Below code is working fine in dev environment - But while moving the same code to production environment its not working and throwing error as "Cannot access a closed stream".

Binary binaryData;
container binData;
System.Int32 netIndex=1,netCount=1;
int bytecount = 0 ;
System.IO.MemoryStream mstream = new System.IO.MemoryStream();

while(bytecount < reportBytes.Length)
{
mstream.WriteByte(reportBytes.GetValue(bytecount));
bytecount++;
}
mstream.Position = 0 ;
pdfreader = new iText.Kernel.Pdf.PdfReader(mstream);
writeproperties.SetStandardEncryption(System.Text.Encoding::UTF8.GetBytes(pwd),System.Text.Encoding::UTF8.GetBytes(pwd),4+2048,2|8);
pdfwriter = new iText.Kernel.Pdf.PdfWriter(mstream,writeproperties);
pdfdocumentation = new iText.Kernel.Pdf.PdfDocument(pdfreader,pdfwriter);
pdfdocumentation.Close();
pdfEncryption = mstream.GetBuffer();

int bytecountEncryp = 0 ;
System.IO.MemoryStream encryptedstream = new System.IO.MemoryStream();
while(bytecountEncryp < pdfEncryption.Length)
{
encryptedstream.WriteByte(pdfEncryption.GetValue(bytecountEncryp));
bytecountEncryp++;
}
encryptedstream.Position = 0;
binaryData = Binary::constructFromMemoryStream(encryptedstream);

if(binaryData)
{
binData = binaryData.getContainer();

}

  • Suggested answer
    Nya Profile Picture
    Nya 29,056 on at
    RE: Sending SSRS report as encrypted pdf document via email not working in production environment in D365 F&O.

    Hi,

    It is recommended to post your issue to the forum of F&O for further help.

    Here is the link:

    Dynamics 365 Finance - Forums, Blogs, Support

Under review

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

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans