1

Does XDocument.Load load the whole file into memory? If not, which method should I use to do that?

I need to have the contents of a temporary file that may be deleted at any time available for processing even after the file was deleted or changed. The files are typically small so having the whole thing in memory is not an issue.

Baruch
  • 20,590
  • 28
  • 126
  • 201

1 Answers1

3

Yes, XDocument.Load("filePath") will load complete file immediately into memory.

MSDN http://msdn.microsoft.com/en-us/library/bb343181.aspx says:

This method uses an underlying XmlReader to read the XML into an XML tree.

To provide full power of XDocument (which is the result of Load method) via LINQ to XML the XML tree must be built immediately.

NOTES: Any manipulation with data in memory will not affect the file and vice versa. The explicit document.Save(path) must be called.... So Load will really read data into memory

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335