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