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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Export XML Encoding UTF-8 Without BOM

(2) ShareShare
ReportReport
Posted on by 89
Hi, I want to export XML with File Encoding "UTF-8"  but the encoding file always "UTF-8 With BOM", please give me solution to export XML with File Encoding "UTF-8".
 
public void writeXmlFile(XmlDocument _xmlDoc)
{
    using (var stream = new System.IO.MemoryStream())
    {
        XMLWriter writer = XMLWriter::newStream(stream); //Convert the Xml to a memory stream and pass it to use File::SendFileToUser method
        _xmlDoc.writeTo(writer);
        writer.flush();

        File::SendFileToUser(stream, 'XmlFile.xml');
    }
}
Categories:
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    239,238 Most Valuable Professional on at
    You should be able to achieve that by using XmlWriterSettings with Encoding = new System.Text.UTF8Encoding(false).
     
    Unfortunately, the X++ class XmlWriterSettings doesn't support it; there you can provide the encoding name only, not additional parametes. But the class is actually just a wrapper of the .NET class, System.Xml.XmlWriterSettings, and you can provide the .NET object in it's constructor.
     
    Therefore I suggest the following:
    System.Xml.XmlWriterSettings netWriterSettings = new System.Xml.XmlWriterSettings();
    netWriterSettings.Encoding = new System.Text.UTF8Encoding(false);
    
    XmlWriterSettings axWriterSettings = new XmlWriterSettings(netWriterSettings);
    
    XMLWriter writer = XMLWriter::newStream(stream, axWriterSettings);
    Alternatively, you could ignore the X++ wrappers and use the .NET API directly.
  • AB-21051008-0 Profile Picture
    89 on at
    Thanks Sir, It's Works!!
  • Martin Dráb Profile Picture
    239,238 Most Valuable Professional on at
    That's good to hear.
    Please don't forget to verify the answer.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 653

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 501 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 298

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans