开发者

How to determine location of IsolatedStorageFile root directory

开发者 https://www.devze.com 2023-01-10 16:23 出处:网络
I\'m using IsolatedStorage for persisting objects, but from time to time I need to manually clean out files from this 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 th开发者_开发问答is 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>>);
}


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?


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消