2

ファイル ストリームを開いて "Length" プロパティを呼び出す以外に、Isolated Storage 内のファイルのサイズを特定する方法が見つからないようです。これを行うより効率的な方法はありますか?

ありがとう

4

2 に答える 2

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;
}
于 2010-09-28T04:09:23.407 に答える
0
long Size = 0L;
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filePath, FileMode.Open, FileAccess.Read, isoFile))
{
  Size = stream.Length;
}
于 2014-08-29T00:53:30.390 に答える