Monday, January 29, 2024

Convert Stream to Base64String in D365FO X++

using Microsoft.Dynamics365.LocalizationFramework;


String getBase64FromString(

            System.IO.Stream        _pdfStream)

    {

        str base64data = '';


        if (_pdfStream != null)

        {

            using (System.IO.Stream fileStream = _pdfStream)

            {

                using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())

                {

                    fileStream.CopyTo(memoryStream);

                    base64data =  ERConversionUtils::StreamToBase64(memoryStream);

                }

            }

        return base64data ;

    }


Condition:

Feature "Utilize application resources to perform CBD documents conversion from Word to PDF format" is enabled,

Then stream aligned to get Base64String.

Workaround logic:

str     fileDownloadURL;

            System.IO.Stream        tempPdfStream;

            fileDownloadURL = File::SendFileToTempStore(_pdfStream, this.parmSaveFilePath());


            tempPdfStream = File::UseFileFromURL(fileDownloadURL);

1 comment:

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...