2010-09-27 97 views

回答

2

我發現了一點點黑客,使其工作。你所要做的就是使用反射來獲取完全合格的文件路徑,文件,然後你想創建一個新的文件信息對象:

//This is the private field name used for reflection 
private const string IsolatedStoreRootDir = "m_RootDir"; 

//This method takes a file path relative to isolated storage 
//and the current store 
private static FileInfo GetFileInfo(string path, IsolatedStorageFile store) 
{ 
    return new FileInfo(GetFullyQualifiedFileName(path, store)); 
} 

//This gets the fully qualified path of the root isolated storage directory 
//then appends the relative path to it. 
private static string GetFullyQualifiedFileName(string path, IsolatedStorageFile store) 
{ 
    return Path.Combine(store.GetType() 
     .GetField(IsolatedStorageFileSystem.IsolatedStoreRootDir, 
     System.Reflection.BindingFlags.NonPublic | 
     System.Reflection.BindingFlags.Instance).GetValue(store).ToString(), path); 
} 

//Here's how it's used 
static void Main(string[] args) 
{ 
    var store = IsolatedStorageFile.GetUserStoreForAssembly(); 

    var length = GetFileInfo("TestFile.txt", store).Length; 
} 
+0

您是否在限制的權限環境中測試?隔離存儲是您唯一的特權時,我認爲這不會起作用。 – 2010-09-29 18:15:22

0
long Size = 0L; 
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filePath, FileMode.Open, FileAccess.Read, isoFile)) 
{ 
    Size = stream.Length; 
}