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

  • SEARCH
  • Home
  • 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 6633873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:51:49+00:00 2026-05-25T22:51:49+00:00

I have to open and read an xml file in my Silverlight application. I

  • 0

I have to open and read an xml file in my Silverlight application. I can’t put this file in resources (my teacher’s will). I tried to use this code:

XmlReader reader = XmlReader.Create("products.xml");

but got an error:

Cannot find file 'products.xml' in the application xap package.

This xml file is currently located in Debug folder next to .xap

What should I do to make it work?

XML file(just in case):

<products>
  <product>
    <name>nameA</name>
    <desc>descA</desc>
    <image>imgA</image>
  </product>
  <product>
    <name>nameB</name>
    <desc>descB</desc>
    <image>imgb</image>
  </product>
  <product>
    <name>nameC</name>
    <desc>descC</desc>
    <image>imgC</image>
  </product>
</products>

Error caught in returnResult(args.Result); of Anthony’s code:

System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid.  Check InnerException for exception details. ---> System.Net.WebException: An exception occurred during a WebClient request. ---> System.NotSupportedException: The URI prefix is not recognized.
   in System.Net.WebRequest.Create(Uri requestUri)
   in System.Net.WebClient.GetWebRequest(Uri address)
   in System.Net.WebClient.OpenReadAsync(Uri address, Object userToken)
   --- The end of stack trace of inner exceptions (my translation) ---
   in System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
   in System.Net.OpenReadCompletedEventArgs.get_Result()
   in ProjektAI.MainPage.<>c__DisplayClass1.<GetStreamFromUri>b__0(Object s, OpenReadCompletedEventArgs args)
  • 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-05-25T22:51:50+00:00Added an answer on May 25, 2026 at 10:51 pm

    You will need the help of WebClient to download the xml file from the web server first. Here is a utility method to help.

     public static void GetStreamFromUri(Uri uri, Action<Stream> returnResult)
     {
          WebClient client = new WebClient();
          client.OpenReadCompleted += (s, args) =>
          {
               returnResult(args.Result);
          };
          client.OpenReadAsync(uri);
     }
    

    Your code would then use:-

    GetStreamFromUri(new Uri("products.xml", UriKind.Relative), stream =>
    {
         using (stream)
         {
             XmlReader reader = XmlReader.Create(stream);
    
             // Rest of reader processing code called here.
         }
    });
    
    //  Note really really well: **Code here will run before XmlReader processing**
    

    Likely the code you’ve written so far works synchronously. Silverlight allows resources found in the XAP to be loaded and processed synchronously. However network operations are always asynchronous. Its my guess that “(my teacher’s will)” is in fact that you learn this important asynchronous aspect of Silverlight coding and what effect it has on the way you need to code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application where I need to open an xml file, modify it,
I'm having some trouble using XmlReader to read an XML file. I can open
I want to read simple excel xml file to dictionary. I have tried to
I need to read a xml file, but I have this error when try
I have a FAT12 image file and I have to open it and read
I have this command in a Rails controller open(source) { |s| content = s.read
I have a open file dialog with three filters: QString fileName = QFileDialog::getOpenFileName( this,
I'm trying to read in an xml file which looks like this <?xml version=1.0
I have an xml file, I want to open it, edit certain CDATA node
I have a simple xml file on my hard drive. When I open it

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.