Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9239857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:05:18+00:00 2026-06-18T08:05:18+00:00

I’m attempting to develop a Windows 7 Phone and I am using an XML

  • 0

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.

The problem is this:

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.

I have tried another solution where I use StreamReader But I am still getting a simular error:

Attempt to access the method failed System.IO.File.OpenText(System.String)

Here is the code that I am using:

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 => d.Element(kml + "name").Value,
                          d => d.Element(kml + "id").Value);

            foreach (var b in dict) {
                Console.WriteLine ("Building Name -> " + b.Key + " Building ID -> " + b.Value);
            }
        }

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.

Hope someone can help

EDIT:

New code –

Dictionary<string, string> 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 => d.Element(kml + "name").Value,
                      d => d.Element(kml + "id").Value);


        return dict;


    }

Error: – ‘NullReferenceException was unhanded’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:05:19+00:00Added an answer on June 18, 2026 at 8:05 am

    Assuming you really are trying to do this as part of a WP7 project (rather than some non-mobile project related to it, e.g. preprocessing) you shouldn’t be using File.OpenText.

    Options:

    • Include the XML in your XAP file, and read from that using Application.GetResourceStream (see this blog post for details)
    • Somehow get the XML into isolated storage, and use the isolated storage API
    • Embed the resource into your assembly, and use Assembly.GetManifestResourceStream.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I'm parsing an XML file, the creators of it stuck in a bunch social

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.