Skip to main content

Notifications

Announcements

No record found.

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

Is it Possible to Convert Base64string to Plain text in blob field in D365 Business central? How?

(0) ShareShare
ReportReport
Posted on by 181

I am getting base64string data in blob field using API. Now I want to convert that Base64string to readable format and want to store that data as xml file. So that I can view that file and download it. 

  • Suggested answer
    user 123 Profile Picture
    user 123 181 on at
    RE: Is it Possible to Convert Base64string to Plain text in blob field in D365 Business central? How?

    Hello,

    Thank you so much for sharing this code snippet of converting "Base64String to text" with me! I tried it and it worked perfectly for me. I really appreciate your help and I learned something new today thanks to you. Thank you again for your contribution to the conversation!

  • Verified answer
    Gianfranco C. Profile Picture
    Gianfranco C. 370 on at
    RE: Is it Possible to Convert Base64string to Plain text in blob field in D365 Business central? How?

    hello,

    to convert the base64 code and store it in a table blob field, you can do it this way:

    var

    RecRef : RecordRef;

    cuTempBlob: Codeunit "Temp Blob";

    DocOutStrem: OutStream;

    Base64Convert: Codeunit "Base64 Convert";

    begin

    cuTempBlob.CreateOutStream(DocOutStrem);

    Base64Convert.FromBase64(base64value, DocOutStrem);

    RecRef.GetTable(Rec);

    cuTempBlob.ToRecordRef(RecRef ,Rec.FieldNo(BlobField));

    RecRef.SetTable(Rec);

    end;

    to read the xml file contained in the blob inside the AL code, you can use XMLDOCUMENT like this

    var

    XmlDoc: XmlDocument;

    inStr : Instream;

    begin

    Rec.CALCFIELDS(BlobField);

    Rec.BlobField.CreateInStream(inStr);

    XmlDocument.ReadFrom(inStr, XmlDoc);

    end;

    from here you can use the methods (XmlDoc.SelectNodes, XmlDoc.SelecSingleNode,...etc)

    look at the documentation to learn more:

    learn.microsoft.com/.../xmldocument-data-type

    if you want to save and download the content in xml files on your machine:

    var

    XmlDoc : XmlDocument;

    inStr : Instream;

    FileName : Test;

    begin

    FileName := 'myXmlFile.xml';

    Rec.CALCFIELDS(BlobField);

    Rec.BlobField.CreateInStream(inStr);

    DownloadFromStream(inStr, '', '', FileName);

    end;

    if it helped you, please select this answer, thank you

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,661 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,379 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans