D365/AX7:Convert A String/Text Into A Memory Stream & Download It As XML File

Requirement & Purpose

Requirement is to create a XML string from D365 Finance & Operation using X++ & downloading it into the user’s browser as a XML file.The purpose of this sample code is to show you how we can convert string or text value into a byte array, converting byte array into memory stream the download it into the user’s browser as a XML file.

Sample Code

[code language = “cpp”]
System.Byte[] reportBytes = new System.Byte[0]();
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
reportBytes = enc.GetBytes(‘YOUR XML STRING/TEXT’);
System.IO.MemoryStream stream = new System.IO.MemoryStream(reportBytes);
FileUploadTemporaryStorageResult result = File::SendFileToTempStore_GetResult(stream, ‘abcd.xml’);
Message::Add(MessageSeverity::Informational, result.getDownloadUrl());
Browser().navigate(result.getDownloadUrl(), true);

Leave a Reply