Search code examples
.netisolatedstorage

How to determine location of IsolatedStorageFile root directory


I'm using IsolatedStorage for persisting objects, but from time to time I need to manually clean out files from this directory. As I persist the files, I want to write the physical location of the directory to the console. There doesn't appear to be an accessible property that returns this information though. How should I do it?

Here is my incomplete code:

using (var store = IsolatedStorageFile.GetMachineStoreForAssembly())
{
   Console.WriteLine("Persisting Hotel to {0}", store.<<INSERT APPROPRIATE PROPERTY>>);
}

Solution

  • Well, I haven't tried this, but I did find a link (wasn't easy to find) that supposedly shows how to do this: http://msmvps.com/blogs/angelhernandez/archive/2008/10/04/retrieving-file-path-from-isolatedstorage.aspx

    Basically the key line of code appears to be:

    fileName = isoStore.GetType.GetField("m_RootDir",Reflection.BindingFlags.NonPublic or Reflection.BindingFlags.Instance).GetValue(isoStore).ToString
    

    I'm not sure if any special permissions have to be set to get this to work.

    Ok, also found a related stackoverflow: Can I get a path for a IsolatedStorage file and read it from external applications?