2010-08-05 17 views
3

我正在使用IsolatedStorage來保存對象,但有時我需要手動清除此目錄中的文件。 當我堅持這些文件時,我想將目錄的物理位置寫入控制檯。似乎沒有可返回此信息的可訪問屬性。 我該怎麼做?如何確定IsolatedStorageFile根目錄的位置

這裏是我的殘缺碼:

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

回答

3

嗯,我沒有試過,但我沒有找到一個鏈接(不容易找到),理應展示瞭如何做到這一點:http://msmvps.com/blogs/angelhernandez/archive/2008/10/04/retrieving-file-path-from-isolatedstorage.aspx

基本上代碼的重點線似乎是:

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

我不知道,如果任何特殊權限必須設置爲得到這個工作。

好了,也找到了相關的計算器:Can I get a path for a IsolatedStorage file and read it from external applications?

1

試試這個:

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