アプリを初めて実行するとき、以下のように、IsolatedStorageFile のテキスト ファイルにいくつかのデフォルトを書き込みます。
if (!settings.Contains("firstrun"))
{
StringBuilder sb = new StringBuilder(); // Use a StringBuilder to construct output.
var store = IsolatedStorageFile.GetUserStoreForApplication(); // Create a store
store.CreateDirectory("testLocations"); // Create a directory
IsolatedStorageFileStream rootFile = store.CreateFile("locations.txt"); // Create a file in the root.
rootFile.Close(); // Close File
string[] filesInTheRoot = store.GetFileNames(); // Store all files names in an array
Debug.WriteLine(filesInTheRoot[0]); // Show first file name retrieved (only one stored at the moment)
string filePath = "locations.txt";
if (store.FileExists(filePath)) {
Debug.WriteLine("Files Exists");
StreamWriter sw =
new StreamWriter(store.OpenFile(filePath,
FileMode.Open, FileAccess.Write));
Debug.WriteLine("Writing...");
sw.WriteLine("Chicago, IL");
sw.WriteLine("Chicago, IL (Q)");
sw.WriteLine("Dulles, VA");
sw.WriteLine("Dulles, VA (Q)");
sw.WriteLine("London, UK");
sw.WriteLine("London, UK (Q)");
sw.WriteLine("San Jose, CA");
sw.WriteLine("San Jose, CA (Q)");
Debug.WriteLine("Writing complete");
}
}
これは機能しているように見えますが、ListPicker にこのテキスト ファイルの内容をアルファベット順に入力する必要があります。
それを行う最善の方法は何ですか?テキスト ファイルからリストを作成し、ListPicker にそのリストを入力しますか?