Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

Simple: Convert Text to Instream

Posted on by 40

Is there a simple and nice way to convert a Text variable to an Instream?

I just want to enable the user to download a file, whose content I already store using a Text var.

My dirty way works as following, but the Record TempBlob is marked for removal:

var
    fileName: Text;
    fileContent: Text;
    istream: InStream;
    oStream: OutStream;
    tempBlob: Record TempBlob temporary;
begin
    // Here some code to fill fileContent and fileName
    tempBlob.WriteAsText(fileContent, TextEncoding::UTF8);
    tempBlob.Blob.CreateInStream(istream, TextEncoding::UTF8);
    DownloadFromStream(istream, 'Export', '', 'All Files (*.*)|*.*', file_name);
end;

  • Verified answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: Simple: Convert Text to Instream

    Hello,

    Go for  Mohana Yadav suggestions you will get some idea.

    Or else by little bit changes on your code will work as shown below.

    procedure DownloadTextToStream()
        var
            fileName: Text;
            fileContent: Text;
            istream: InStream;
            oStream: OutStream;
            tempBlob: Codeunit "Temp Blob";
        begin
            // Here some code to fill fileContent and fileName
            Clear(tempBlob);
            tempBlob.CreateOutStream(oStream, TEXTENCODING::UTF8);
            oStream.WriteText(fileContent);
            tempBlob.CreateInStream(istream);
            DownloadFromStream(istream, 'Export', '', 'All Files (*.*)|*.*', fileName);
        end;

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,139 Super User 2024 Season 2 on at
    RE: Simple: Convert Text to Instream

    Please try function FromBase64 in codeunit 4110 "Base64 Convert"

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

Featured topics

Product updates

Dynamics 365 release plans