This project is read-only.

Save to IsolatedStorage, load then save to media library?

Jun 25, 2012 at 11:09 PM

I have the following code but I run into a invalidoperationexception below when trying to save to an isolated storage, load it then to be saved to the media library.

Is this not possible?

ExtendedImage myImage = element.ToImage();

            using (MemoryStream stream = new MemoryStream())
            {
                myImage.WriteToStream(stream, imgName);
            }


            MemoryStream finalstream = new MemoryStream();
            finalstream = (MemoryStream)myImage.ToStream();

            using (finalstream)
            {
                var myStore = IsolatedStorageFile.GetUserStoreForApplication();
                if (myStore.FileExists(imgName))
                {
                    myStore.DeleteFile(imgName);
                }
                IsolatedStorageFileStream fs = myStore.CreateFile(imgName);
                fs.Write(finalstream.GetBuffer(), 0, (int)finalstream.Length);
                fs.Close();

                fs = myStore.OpenFile(imgName, FileMode.Open, FileAccess.Read);
                GINternetMobileWP7.App.AppPages.ginternetmainpage.mainmedlibrary.SavePicture(imgName, fs); ---> INVALID OPERATION EXCEPTION!
                fs.Close();

                if (myStore.FileExists(imgName))
                {
                    myStore.DeleteFile(imgName);
                }
            }

Sorry if this is a repost I could not find any posts on this topic.

Thanks.

Joe