Export (0) Print
Expand All

XmlWriterSettings.CloseOutput Property

Gets or sets a value indicating whether the XmlWriter should also close the underlying stream or TextWriter when the Close method is called.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public bool CloseOutput { get; set; }

Property Value

Type: System.Boolean
true to also close the underlying stream or TextWriter; otherwise, false. The default is false.

This setting is useful when you wish to write XML to a stream, and then add extra information to the end of the stream after the XmlWriter has finished writing.

This property only applies to XmlWriter instances that output XML content to a stream or TextWriter; otherwise, this setting is ignored.

The following example writes an XML fragment to a memory stream.

XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.CloseOutput = false;

// Create the XmlWriter object and write some content.
MemoryStream strm = new MemoryStream();
XmlWriter writer = XmlWriter.Create(strm, settings);
writer.WriteElementString("orderID", "1-456-ab");
writer.WriteElementString("orderID", "2-36-00a");
writer.Flush();
writer.Close();

// Do additonal processing on the stream.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft