Question

I'm trying to implement SkyDrive backup into my app. Everything is working fine except I have no idea how to easily save stream (with downloaded backup from SkyDrive) into Isolated Storarage.

I know that I could deserilaze the stream and than save it, but it would unnecessarily complicated.

So, here's my problem:

I have a Stream with the file from SkyDrive and I need to save it into IsolatedStorage as file 'Settings.XML'.

So basicly I need to Write the 'stream' into Settings.xml file in Isolated Storage

        static void client_DownloadCompleted(object sender, LiveDownloadCompletedEventArgs e, string saveToPath)
    {
        Stream stream = e.Result; //Need to write this into IS

        try
        {
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(saveToPath, FileMode.Create))
                {
                    //How to save it?

                }
            }
        }...

Thanks!

Was it helpful?

Solution

Use the steam's CopyTo() method - http://msdn.microsoft.com/en-us/library/dd782932.aspx

using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(saveToPath, FileMode.Create))    
{    
  stream.CopyTo(fileStream);
} 

OTHER TIPS

The quickest and simplest thung to do is to copy the bytes block by block from one stream to the next - see the accepted answer in How do I copy the contents of one stream to another?


However, if there is any chance that the network stream will be corrupt or contain invalid data, then it might be worth deserializing the stream and validating before you save it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top