あなたはちょうどあなたが以下の(あなたは、リソースへのファイルのビルドアクションを設定していると仮定)を行うことができ、それを読むためにそれを開いている場合は、次の
System.IO.Stream myFileStream = Application.GetResourceStream(new Uri(@"/YOURASSEMBLY;component/xmlfiles/mensen.xml",UriKind.Relative)).Stream;
あなたが読み取り/このファイルを書き込もうとしている場合隔離ストレージにコピーする必要があります。 (using System.IO.IsolatedStorage
を追加してください)
あなたはそうするためにこれらのメソッドを使用することができます。いずれの場合も
private void CopyFromContentToStorage(String fileName)
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
System.IO.Stream src = Application.GetResourceStream(new Uri(@"/YOURASSEMBLY;component/" + fileName,UriKind.Relative)).Stream;
IsolatedStorageFileStream dest = new IsolatedStorageFileStream(fileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, store);
src.Position = 0;
CopyStream(src, dest);
dest.Flush();
dest.Close();
src.Close();
dest.Dispose();
}
private static void CopyStream(System.IO.Stream input, IsolatedStorageFileStream output)
{
byte[] buffer = new byte[32768];
long TempPos = input.Position;
int readCount;
do
{
readCount = input.Read(buffer, 0, buffer.Length);
if (readCount > 0) { output.Write(buffer, 0, readCount); }
} while (readCount > 0);
input.Position = TempPos;
}
、ファイルがリソースに設定されていると、あなたの名前でYOURASSEMBLYの部品を交換してくださいアセンブリ。あなたのファイルにアクセスするには、上記の方法を使用して
だけでこれを行う:あなたの意図は、その後ChrisKentの提案ごとに分離ストレージにコピーする、このファイルを変更することができるようになる場合
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
if (!store.FileExists(fileName))
{
CopyFromContentToStorage(fileName);
}
store.OpenFile(fileName, System.IO.FileMode.Append);
こんにちはtheXsが、良いです。ファイルを読みたいだけの場合は、コンテンツやリソースとしてxapファイルから読み込むのに問題はありません(それぞれ、負荷の海岸 - 遅延ロードとスタートアップを引き起こしたい場合に応じて)CtackeとMattが提案します。 –