CultureAndRegionInfoBuilder.Save Method

Writes an XML representation of the current CultureAndRegionInfoBuilder object to the specified file.

Namespace: System.Globalization
Assembly: sysglobl (in sysglobl.dll)

public void Save (
	string filename
public void Save (
	String filename
public function Save (
	filename : String
Not applicable.



The name of a file to contain the XML representation of this custom culture.

Exception typeCondition


filename is a null reference (Nothing in Visual Basic).


filename is an empty string ("").


The value of a property of a DateTimeFormatInfo, TextInfo, or NumberFormatInfo object contained in the current CultureAndRegionInfoBuilder object is invalid.

The current CultureAndRegionInfoBuilder object is written to the filename parameter in an XML format called Locale Data Markup Language (LDML) version 1.1. The CreateFromLdml method performs the reverse operation of the Save method.

For more information about the LDML standard, see Unicode Technical Standard #35, "Locale Data Markup Language (LDML)," at the Unicode home site.

The following code example demonstrates the Save and CreateFromLdml methods.

// This example demonstrates the CultureAndRegionInfoBuilder.Save and 
// CreateFromLdml methods.
// Compile this example with a reference to sysglobl.dll.

using System;
using System.Globalization;
using System.IO;
using System.Xml;

class Sample 
    public static void Main() 
    string savedCARIB = "mySavedCARIB.xml";
    string msg1 = "The name of the original CultureAndRegionInfoBuilder" +
                  " is \"{0}\".";
    string msg2 = "Reconstituting the CultureAndRegionInfoBuilder object " +
                  "from \"{0}\".";
    string msg3 = "The name of the reconstituted CultureAndRegionInfoBuilder" +
                  " is \"{0}\".";

// Construct a new, privately used culture that extends the en-US culture 
// provided by the .NET Framework. In this sample, the CultureAndRegion-
// Types.Specific parameter creates a minimal CultureAndRegionInfoBuilder 
// object that you must populate with culture and region information.

    CultureAndRegionInfoBuilder cib1 = null;
    CultureAndRegionInfoBuilder cib2 = null;
    try {
        cib1 = new CultureAndRegionInfoBuilder(
                           "x-en-US-sample", CultureAndRegionModifiers.None);
    catch (ArgumentException ae)

// Populate the new CultureAndRegionInfoBuilder object with culture information.
    CultureInfo ci = new CultureInfo("en-US");

// Populate the new CultureAndRegionInfoBuilder object with region information.
    RegionInfo  ri = new RegionInfo("US");

// Display a property of the new custom culture.
    Console.WriteLine(msg1, cib1.CultureName);

// Save the new CultureAndRegionInfoBuilder object in the specified file in
// LDML format. The file is saved in the same directory as the application 
// that calls the Save method.

    Console.WriteLine("Saving the custom culture to a file...");
    try {
        cib1.Save( savedCARIB );
    catch (IOException exc)
        Console.WriteLine("** I/O exception: {0}", exc.Message);

// Create a new CultureAndRegionInfoBuilder object from the persisted file.
    Console.WriteLine(msg2, savedCARIB);
    try {
        cib2 = CultureAndRegionInfoBuilder.CreateFromLdml( savedCARIB );
    catch (XmlException xe)
        Console.WriteLine("** XML validation exception: {0}", xe.Message);

// Display a property of the resonstituted custom culture.
    Console.WriteLine(msg3, cib2.CultureName);

// At this point you could call the Register method and make the reconstituted
// custom culture available to other applications. The mySavedCARIB.xml file
// remains on your computer.

This code example produces the following results:

The name of the original CultureAndRegionInfoBuilder is "x-en-US-sample".
Saving the custom culture to a file...
Reconstituting the CultureAndRegionInfoBuilder object from "mySavedCARIB.xml".
The name of the reconstituted CultureAndRegionInfoBuilder is "x-en-US-sample".


Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0