Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does XmlDocument.Load(String) seem to want read-write access?

Tags:

c#

.net

xml

According to MSDN the .NET XmlDocument.Load(String) method requires write access to the underlying file. The exceptions list says

UnauthorizedAccessException :  filename specified a file that is read-only....

My question boils down to

  • Is it even true that read-write access is needed, or is this just a documentation error?
  • Does it mean that the file is kept open during the lifetime of the object?
  • Does it mean that modifications to the the XmlDocument and its sub-nodes can result in live modifications to the file on disk? Even without an explicit save.
like image 809
Adrian Ratnapala Avatar asked Nov 12 '22 05:11

Adrian Ratnapala


1 Answers

Is it even true that read-write access is needed

  • Looks like documentation bug. When loading, XmlDocument creates XmlReader, which, AFAIK, doesn't throws such exceptions.

Does it mean that the file is kept open during the lifetime of the object

  • No, file becomes closed after reading.

Does it mean that modifications to the the XmlDocument and its sub-nodes can result in live modifications to the file on disk

  • No, because the file is closed.
like image 125
Dennis Avatar answered Nov 14 '22 21:11

Dennis