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 7967273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:39:08+00:00 2026-06-04T06:39:08+00:00

I am downloading a xml file from the internet and save it in isolated

  • 0

I am downloading a xml file from the internet and save it in isolated storage. If I try to read it I get an error:

Data at the root level is invalid. Line 1, position 1.

string tempUrl = "http://xxxxx.myfile.xml"; // changed
WebClient client = new WebClient();
client.OpenReadAsync(new Uri(tempUrl));
client.OpenReadCompleted += new OpenReadCompletedEventHandler(delegate(object sender, OpenReadCompletedEventArgs e) {

StreamWriter writer = new StreamWriter(new IsolatedStorageFileStream("myfile.xml", FileMode.Create, FileAccess.Write, myIsolatedStorage));
 writer.WriteLine(e.Result);
 writer.Close();
});

This is how I download and save the file…

And I try to read it like that:

IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("myfile.xml", FileMode.Open, FileAccess.Read);
XDocument xmlDoc = XDocument.Load(fileStream);

This is where I get the error…

I have no problem reading the same file without downloading and saving it to isolated storage… so there must be the fault.

  • 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-04T06:39:09+00:00Added an answer on June 4, 2026 at 6:39 am

    This:

    writer.WriteLine(e.Result);
    

    doesn’t do what you think it does. It’s just calling ToString() on a Stream, and writing the result to a file.

    I suggest you avoid using a StreamWriter completely, and simply copy from e.Result straight to the IsolatedStorageFileStream:

    using (var output = new IsolatedStorageFileStream("myfile.xml", FileMode.Create, 
                                        FileAccess.Write, myIsolatedStorage))
    {
        CopyStream(e.Result, output);
    }
    

    where CopyStream would be a method to just copy the data, e.g.

    public static void CopyStream(Stream input, Stream output)
    {
        byte[] buffer = new byte[8 * 1024];
        int read;
        while((read = input.Read (buffer, 0, buffer.Length)) > 0)
        {
            output.Write (buffer, 0, read);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I am downloading and parsing my data from an XML file that is
I am downloading a CSV file from another server as a data feed from
I need help with downloading from webserver... What i currently do is get XML
) I make the download of an xml file from the internet to the
I make the download of an xml file from the internet to the memory
i need to save a xml file from a server.. i found a code
I am downloading an XML file from a site I created and it works
I used following code for downloading XML file from ftp to android phone memory
I am downloading xml file from local host to SD card. I want to
I'm writing application for downloading CSV file from web and inserting data into table

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.