3

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>>);
}
Scott Ferguson
  • 7,690
  • 7
  • 41
  • 64

2 Answers2

3

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?

Community
  • 1
  • 1
Mafu Josh
  • 2,523
  • 1
  • 23
  • 25
0

Try this:

using System.IO.IsolatedStorage;
using System.Reflection;

var store = IsolatedStorageFile.GetMachineStoreForAssembly();
var pathName = store.GetType().GetField("m_RootDir", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(store).ToString();
perror
  • 7,071
  • 16
  • 58
  • 85
Njguerra
  • 9
  • 1