# C1.Win.FlexGrid.C1FlexGridBase.WriteXml

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.WriteXml*">WriteXml Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.WriteXml*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_System_String_C1_Win_FlexGrid_XmlOptions_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.WriteXml(System.String,C1.Win.FlexGrid.XmlOptions)">WriteXml(string, XmlOptions)</h4>
<div class="markdown level1 summary"><p>Saves the grid contents to an Xml document.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public void WriteXml(string fileName, XmlOptions options = XmlOptions.All)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub WriteXml(fileName As String, Optional options As XmlOptions = XmlOptions.All)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></td>
      <td><span class="parametername">fileName</span></td>
      <td><p>Name of the file to save, including the path.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="C1.Win.FlexGrid.XmlOptions.html">XmlOptions</a></td>
      <td><span class="parametername">options</span></td>
      <td><p>Options that allows to choose which elements of FlexGrid should be saved</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_System_String_C1_Win_FlexGrid_XmlOptions__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>The grid serializes all its contents into the Xml document, including the 
data stored in the cells, row and column properties, styles, images, etc.</p>
<p>Objects of custom types stored in the grid are also serialized as long as
they have an associated <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.componentmodel.typeconverter">TypeConverter</a> that provides conversions to
and from string.</p>
<p>The <a class="xref" href="C1.Win.FlexGrid.C1FlexGridBase.WriteXml.html#C1_Win_FlexGrid_C1FlexGridBase_WriteXml_System_String_C1_Win_FlexGrid_XmlOptions_">WriteXml(string, XmlOptions)</a> method has several overloads that allow you to 
save several grids into a single Xml document, along with other information stored
in the Xml document.</p>
</div>
<h5 id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_System_String_C1_Win_FlexGrid_XmlOptions__examples">Examples</h5>
<p>The code below saves a grid into an Xml file:</p>
<pre><code class="lang-csharp">// save a grid into am Xml file
flex.WriteXml(fileName);</code></pre>
<p>The code below saves two grids into an Xml file, then reads them back in reverse order:</p>
<pre><code class="lang-csharp">// prepare XmlTextWriter
XmlTextWriter w = new XmlTextWriter(fileName, new UTF8Encoding(false));
w.Formatting = Formatting.Indented;
w.WriteStartDocument();
w.WriteStartElement("Grids");

// save first grid
w.WriteStartElement(c1FlexGrid1.Name);
c1FlexGrid1.WriteXml(w);
w.WriteEndElement();

// save second grid
w.WriteStartElement(c1FlexGrid2.Name);
c1FlexGrid2.WriteXml(w);
w.WriteEndElement();

// close document
w.WriteEndElement();
w.Close();

// load document from file
XmlDocument doc = new XmlDocument();
doc.Load(fileName);
XmlNode n = doc.SelectSingleNode("Grids");

// load grids in reverse order
c1FlexGrid2.ReadXml(n.ChildNodes[0]);
c1FlexGrid1.ReadXml(n.ChildNodes[1]);</code></pre>



<a id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.WriteXml*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_System_IO_TextWriter_C1_Win_FlexGrid_XmlOptions_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.WriteXml(System.IO.TextWriter,C1.Win.FlexGrid.XmlOptions)">WriteXml(TextWriter, XmlOptions)</h4>
<div class="markdown level1 summary"><p>Saves the grid contents to an Xml document.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public void WriteXml(TextWriter tw, XmlOptions options = XmlOptions.All)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub WriteXml(tw As TextWriter, Optional options As XmlOptions = XmlOptions.All)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.io.textwriter">TextWriter</a></td>
      <td><span class="parametername">tw</span></td>
      <td><p>The <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.io.textwriter">TextWriter</a> where the document is saved.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="C1.Win.FlexGrid.XmlOptions.html">XmlOptions</a></td>
      <td><span class="parametername">options</span></td>
      <td><p>Options that allows to choose which elements of FlexGrid should be saved</p>
</td>
    </tr>
  </tbody>
</table>


<a id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.WriteXml*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_System_IO_Stream_C1_Win_FlexGrid_XmlOptions_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.WriteXml(System.IO.Stream,C1.Win.FlexGrid.XmlOptions)">WriteXml(Stream, XmlOptions)</h4>
<div class="markdown level1 summary"><p>Saves the grid contents to an Xml document.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public void WriteXml(Stream stream, XmlOptions options = XmlOptions.All)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub WriteXml(stream As Stream, Optional options As XmlOptions = XmlOptions.All)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.io.stream">Stream</a></td>
      <td><span class="parametername">stream</span></td>
      <td><p>The <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.io.stream">Stream</a> where the document is saved.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="C1.Win.FlexGrid.XmlOptions.html">XmlOptions</a></td>
      <td><span class="parametername">options</span></td>
      <td><p>Options that allows to choose which elements of FlexGrid should be saved</p>
</td>
    </tr>
  </tbody>
</table>


<a id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.WriteXml*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_System_Xml_XmlTextWriter_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.WriteXml(System.Xml.XmlTextWriter)">WriteXml(XmlTextWriter)</h4>
<div class="markdown level1 summary"><p>Saves the grid contents to an Xml document.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public virtual void WriteXml(XmlTextWriter w)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Overridable Sub WriteXml(w As XmlTextWriter)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="xref">XmlTextWriter</span></td>
      <td><span class="parametername">w</span></td>
      <td><p>The <span class="xref">System.Xml.XmlTextWriter</span> where the document is saved.</p>
</td>
    </tr>
  </tbody>
</table>


<a id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.WriteXml*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGridBase_WriteXml_System_Xml_XmlTextWriter_C1_Win_FlexGrid_XmlOptions_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.WriteXml(System.Xml.XmlTextWriter,C1.Win.FlexGrid.XmlOptions)">WriteXml(XmlTextWriter, XmlOptions)</h4>
<div class="markdown level1 summary"><p>Saves the grid contents to an Xml document.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public virtual void WriteXml(XmlTextWriter w, XmlOptions options)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Overridable Sub WriteXml(w As XmlTextWriter, options As XmlOptions)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="xref">XmlTextWriter</span></td>
      <td><span class="parametername">w</span></td>
      <td><p>The <span class="xref">System.Xml.XmlTextWriter</span> where the document is saved.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="C1.Win.FlexGrid.XmlOptions.html">XmlOptions</a></td>
      <td><span class="parametername">options</span></td>
      <td><p>Options that allows to choose which elements of FlexGrid should be saved</p>
</td>
    </tr>
  </tbody>
</table>
</div>
