Export (0) Print
Expand All

XmlTextWriter Constructor (String, Encoding)

Creates an instance of the XmlTextWriter class using the specified file.

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

public XmlTextWriter(
	string filename,
	Encoding encoding
)

Parameters

filename
Type: System.String
The filename to write to. If the file exists, it truncates it and overwrites it with the new content.
encoding
Type: System.Text.Encoding
The encoding to generate. If encoding is null it writes the file out as UTF-8, and omits the encoding attribute from the ProcessingInstruction.

ExceptionCondition
ArgumentException

The encoding is not supported; the filename is empty, contains only white space, or contains one or more invalid characters.

UnauthorizedAccessException

Access is denied.

ArgumentNullException

The filename is null.

DirectoryNotFoundException

The directory to write to is not found.

IOException

The filename includes an incorrect or invalid syntax for file name, directory name, or volume label syntax.

SecurityException

The caller does not have the required permission.

NoteNote

In the .NET Framework version 2.0 release, the recommended practice is to create XmlWriter instances using the XmlWriter.Create method and the XmlWriterSettings class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft