Load Method (String)

XmlDocument.Load Method (String)


Loads the XML document from the specified URL.

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

public virtual void Load(
	string filename


Type: System.String

URL for the file containing the XML document to load. The URL can be either a local file or an HTTP URL (a Web address).

Exception Condition

There is a load or parse error in the XML. In this case, a FileNotFoundException is raised.


filename is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.


filename is null.


The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.


The specified path is invalid (for example, it is on an unmapped drive).


An I/O error occurred while opening the file.


filename specified a file that is read-only.


This operation is not supported on the current platform.


filename specified a directory.


The caller does not have the required permission.


The file specified in filename was not found.


filename is in an invalid format.


The caller does not have the required permission.


The Load method always preserves significant white space. The PreserveWhitespace property determines whether or not insignificant white space, that is white space in element content, is preserved. The default is false; white space in element content is not preserved.

If you want validation to occur, you can create a validating XmlReader instance by using the XmlReaderSettings class and the Create method. For more information, see the Remarks section of the XmlReader reference page.

This method is a Microsoft extension to the Document Object Model (DOM).

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft