How do I load an XML document in read-only mode?
I have an XML file which is opened in another process and I want to load it in my C# application as read-only.
XmlDocument.Load("file.xml")
obviously throws this error:
Process cannot access a file because it is being used by another process
So I tried stream reader too:
FileStream fs = new FileStream("file.xml", FileMode.Open, FileAccess.Read);
xmldoc.Load(fs);
But it also throws the same error. So how can I access my XML Document in read-only mode?
Update
I tried XPathDocument
and FileStream("file.xml", FileMode.Open, FileAccess.Read,FileShare.Read)
as well. But neither of them solved the problem.