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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
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.

(0) ShareShare
ReportReport
Posted on by 27,827 Moderator

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();

}

I have the same question (0)
  • Suggested answer
    Nya Profile Picture
    29,060 on at

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 74

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans