web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Best way to generate and return large XML files without saving locally? (RunBaseBatch)

(1) ShareShare
ReportReport
Posted on by 18
Hello everybody

I am currently generating an XML file inside X++ and I save it locally before streaming it to the user.

Here is the code:

XmlDocument xmlDoc;

xmlFileName = _nameFile+'.xml'; //
xmlFilePath = System.IO.Path::GetTempPath() + xmlFileName;
 
xmlDoc.save(xmlFilePath);
 
System.IO.MemoryStream memoryStream;

memoryStream = new System.IO.MemoryStream(System.IO.File::ReadAllBytes(xmlFilePath));
 
File::SendFileToUser(memoryStream, xmlFilename);
 

This works, but:

 Problem

In the future, the generated XML files may become very large.

Saving large files on the local disk is not the best option.

My Question

Is there an alternative solution that allows me to:

  • Generate and return the XML without saving it to a local file,

  • Or store it somewhere safer

  • And still download it to the user when needed?

 

Thanks for the help.

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    300,293 Super User 2025 Season 2 on at
    Best way to generate and return large XML files without saving locally? (RunBaseBatch)
    Hi,
     
    Can you please clarify if your question is related to Dynamics AX (2012 or before) or Dynamics 365 F&O? You used both tags, which is contradictory. Most likely your question is about F&O, but please confirm.

    Anyway, what is the reason to save it locally? You can directly get the XML content in a memory stream.
  • Suggested answer
    Martin Dráb Profile Picture
    237,089 Most Valuable Professional on at
    Best way to generate and return large XML files without saving locally? (RunBaseBatch)
    What is the best option depends on what you do with the XML document. Unfortunately, you gave us no description and your code snippet is completely missing this part.
     
    If you want to keep using XmlDocument class, notice that it's a wrapper around System.Xml.XmlDocument, which has a method for saving to a Stream. You can create an extension of XmlDocument and a method exposing document.Save().
     
    Nevertheless the idea that saving large files on disk sounds very strange to me. This is what disks are for. What you should be more concerned about is keeping large files in RAM, which is normally much smaller than disk space.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 667 Most Valuable Professional

#2
CU05031448-0 Profile Picture

CU05031448-0 584

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 554 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans