Search code examples
vbawindows-phone-8visual-studio-2013

Uploading xml to windows phone 8 VB


    `Dim medium As String = TextBox1.Text
    Dim data_xml = XElement.Load("Assets\Manager.xml")

    'next quaries the xml for desired attributes
    Dim query = From DataTable1 In data_xml.Descendants("DataTable1")
                Where (DataTable1.Attribute("Medium").Value = medium)
                Select Uname = DataTable1.Attribute("Username").Value

    For Each result In query
    'displays results to textbox
        TextBox2.Text = result
    Next

I try to use this code to read from an xml file in the assets but the file does not seem to exist

At the declaration of the xelement.load("Assets\Manager.xml") I get this error

An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code

Additional information: Could not find file 'C:\Data\SharedData\PhoneTools\AppxLayouts\d5d3a1e7-56d7-477c-bcd2-f949f3374de1VS.Debug_AnyCPU.NAME\Assets\Manager.xml'.

If there is a handler for this exception, the program may be safely continued.

Any ideas?


Solution

  • Steps to make it work:

    • Change Manager.xml Build action to Content
    • Change Copy to output directory to Copy if newer
    • Load file using XElement.Load("Assets/Manager.xml");

    Edit:

    Ok, since you are not willing to share more of the code even though you ask for help, there's nothing else I can do but put up an example :)

    "Software" below, implemented in Visual Basic, reads and displays XML file named Manager.xml, that is set as Content in WP8 project. Working example can be found at https://github.com/mikkoviitala/read-content-xml

    imgur