Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IsolatedStorageFile's MoveFile() method throws IsolatedStorageException

Description:

The code below is the simplest code I could write which causes the failure. I've also tried: putting the CreateFile and MoveFile in different using statements, putting them in different xaml pages, moving the file into a subdirectory with a new filename, moving it into a subdirectory with the same filename. They all throw the same exception. CopyFile throws the same exception in all circumstances.

Question is--what incredibly simple thing am I not accounting for?

  1. Open a new Silverlight for Windows Phone 7 project targeting Windows Phone 7.1.
  2. Open App.xaml.cs.
  3. Paste the following lines of code into Application_Launching:

    using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
    {
        isf.CreateFile("hello.txt");
        isf.MoveFile("hello.txt", "hi.txt");
    }
  4. Click start debugging, targeting emulator or device.

Expected: creates a file named "hello.txt", then (effectively) renames "hello.txt" to "hi.txt".
Actual: throws exception below.

System.IO.IsolatedStorage.IsolatedStorageException was unhandled
  Message=An error occurred while accessing IsolatedStorage.
  StackTrace:
       at System.IO.IsolatedStorage.IsolatedStorageFile.MoveFile(String sourceFileName, String destinationFileName)
       at PhoneApp4.App.Application_Launching(Object sender, LaunchingEventArgs e)
       at Microsoft.Phone.Shell.PhoneApplicationService.FireLaunching()
       at Microsoft.Phone.Execution.NativeEmInterop.FireOnLaunching()
like image 633
user1510416 Avatar asked Mar 14 '26 13:03

user1510416


1 Answers

You should call Close after you create the file.

IsolatedStorageFileStream helloFile = store.CreateFile("hello.txt");
helloFile.Close();
isf.MoveFile("hello.txt", "hi.txt");
like image 113
MBen Avatar answered Mar 17 '26 02:03

MBen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!