locked
OOB Silverlight app, trouble with reading local xml file RRS feed

  • Question

  • I have created an Out Of Browser Silverlight app and I'm having trouble loading an xml file.

    In the "My Documents" folder I have 2 xml files that I load at various times in my application. The path locations are as follows.

    File1 = testApp\Programs\models.xml

    File2 = testApp\Database\Stats.xml

    Loading and saving File1 works fine but loading File2 gives me the following error

    Cannot open 'file://gbbed01fi01/HOME01/GBCO0101/My Documents/testApp/Database/Stats.xml'. The Uri parameter must be a relative path pointing to content inside the Silverlight application's XAP package. If you need to load content from an arbitrary Uri, please see the documentation on Loading XML content using WebClient/HttpWebRequest.

    Saving File2 works fine also so why do I get the error while trying to load File2?

    Tuesday, December 21, 2010 10:34 AM

Answers

  • Problem solved, my own stupid fault.

    My code was the following.

    xmlFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
            xmlFilePath + "Stats.xml");
    
          XDocument xDocStat = null;
             if (File.Exists(xmlFilePath))
            {
                        xDocStat = XDocument.Load(xmlFilePath);
                      }

    Should have been

    xmlFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
            xmlFilePath + "Stats.xml");
    
          XDocument xDocStat = null;
            if (File.Exists(xmlFilePath))
            {
              FileStream fs = File.OpenRead(xmlFilePath);
              xDocStat = XDocument.Load(fs);
              fs.Close();
            }
    • Marked as answer by GaztheLegend Tuesday, December 21, 2010 2:06 PM
    Tuesday, December 21, 2010 2:05 PM