title: Visual studio cannot locate XML file
body: <p>I'm attempting to develop a Windows 7 Phone and I am using an XML file that I need to parse and then perform a Linq query on. </p>
  
  <p>The problem is this:</p>
  
  <p>Whenever I try to access the file (it is stored locally) it brings back an error saying the file cannot be found as it's not part of the XAP package. </p>
  
  <p>I have tried another solution where I use <code>StreamReader</code> But I am still getting a simular error:</p>
  
  <blockquote>
    <p>Attempt to access the method failed System.IO.File.OpenText(System.String)</p>
  </blockquote>
  
  <p>Here is the code that I am using:</p>
  
  <pre><code>using (StreamReader reader = File.OpenText("C:/Users/Desktop/Assign/obj/Debug/buildings.kml"))
          {
              var xdoc = XDocument.Load ("buildings.kml");
              XNamespace kml = "http://www.opengis.net/kml/2.2";
  
              var dict = xdoc.Descendants(kml + "Placemark")
                            .ToDictionary(d =&gt; d.Element(kml + "name").Value,
                            d =&gt; d.Element(kml + "id").Value);
  
              foreach (var b in dict) {
                  Console.WriteLine ("Building Name -&gt; " + b.Key + " Building ID -&gt; " + b.Value);
              }
          }
  </code></pre>
  
  <p>The file is located in: > C:/Users/Desktop/Assign/obj/Debug/buildings.kml so I cannot see the problem. Outside of Visual Studio, I can read in the .xml file fine.</p>
  
  <p>Hope someone can help</p>
  
  <p>EDIT:</p>
  
  <p>New code -</p>
  
  <pre><code>Dictionary&lt;string, string&gt; getBuildingNames()
      {
          Uri uri = new Uri(@"Data\mydata.kml", UriKind.Relative);
  
          StreamResourceInfo sri = Application.GetResourceStream(uri);
  
          StreamReader sr = new StreamReader(sri.Stream);
  
          var xdoc = XDocument.Load(sr);
          XNamespace kml = "http://www.opengis.net/kml/2.2";
  
          var dict = xdoc.Descendants(kml + "Placemark")
                        .ToDictionary(d =&gt; d.Element(kml + "name").Value,
                        d =&gt; d.Element(kml + "id").Value);
  
  
          return dict;
  
  
      }
  </code></pre>
  
  <p>Error: - 'NullReferenceException was unhanded' </p>