6

This is probably a really simple thing, but I haven't been able to find it, and I'm probably just searching for the wrong thing...

XmlTextReader --> Does it lock the file you're reading? I'm using reader.Read() and that's about it.

Samuel
  • 37,778
  • 11
  • 85
  • 87
Matt Grande
  • 11,964
  • 6
  • 62
  • 89

1 Answers1

20

When you create a new XmlTextReader providing a string, it will lock the file with a write lock (but not a read lock); however, if you provide it a Stream, it would depend on the stream itself.

FileStream stream = new FileStream(@"myfile.xml", FileMode.Open,
                            FileAccess.Read, FileShare.ReadWrite);
XmlTextReader reader = new XmlTextReader(stream);

You can now read without having a lock.

Samuel
  • 37,778
  • 11
  • 85
  • 87