Wednesday, August 25, 2021

Converting string to stream in Dynamics 365 finance and operations

 

/// <summary>

    /// Converts string to stream

    /// </summary>

    /// <param name="_record">

    /// String record to be converted to stream

    /// </param>

    /// <param name="_encoding">

    /// Encoding format

    /// </param>

    public static MemoryStream convertStringToStream(str _record, System.Text.Encoding _encoding)

    {

        System.Byte[]  byteArray =   new System.Byte[0]();


        if(_encoding == System.Text.Encoding::Unicode)

        {

            byteArray = System.Text.Encoding::Unicode.GetBytes(_record);

        }

        else

        {

            byteArray = System.Text.Encoding::ASCII.GetBytes(_record);

        }


        return  new MemoryStream( byteArray );

    }

No comments:

Post a Comment