XmlTextWriter Constructor (String, Encoding)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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.

Exception Condition
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.

System_CAPS_noteNote

Starting with the .NET Framework 2.0, we recommend that you create XmlWriter instances by using the XmlWriter.Create method and the XmlWriterSettings class to take advantage of new functionality.

.NET Framework
Available since 1.1
Return to top
Show: