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

}

  • Suggested answer
    Nya Profile Picture
    29,060 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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 32 Super User 2025 Season 1

#2
Sahra Profile Picture

Sahra 21

#3
Mansi Soni Profile Picture

Mansi Soni 15

Overall leaderboard

Product updates

Dynamics 365 release plans