我试图将数组中的所有数据转换为文本文件,以便逐个读取所有项并将其保存到独立存储中并在另一个存储中显示出来页面列表框。将数组转换为文本文件并存储到独立存储中
我试过这个,但我遇到错误,指出“操作不允许IsolatedStorageFileStream”。我需要帮助,请尽快回到我身边。谢谢!
//save list to favourite list
private void addListBtn_Click(object sender, RoutedEventArgs e)
{
///////for-loop to access userDrinksList
//////transform array into textfile, one line for each drink
///////write in quantity of file into isolated storage using write line function
for (int i = 0; i < (Application.Current as App).userDrinksList.Count; i++)
{
//Obtain the virtual store for application
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
//Create a new folder and call it "ListFolder"
storage.CreateDirectory("ListFolder");
//Create a new file and assign a StreamWriter to the store and this new file (myFile.txt)
//Also take the text contents from the txtWrite control and write it to myFile.txt
// StreamReader readFile = null;
StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("ListFolder\\myFile.txt", FileMode.OpenOrCreate, storage));
StreamReader readFile = new StreamReader(new IsolatedStorageFileStream("ListFolder\\myFile.txt", FileMode.Open, storage));
string myFile = readFile.ReadToEnd();
string[] lines = myFile.Split(System.Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
//write content inside myFile.txt
writeFile.WriteLine(myFile);
//retrieveDrinksListBox.Items.AddRange(lines);
//writeFile.Close();
}
这与您最后一个问题有什么不同? http://stackoverflow.com/questions/5740729/how-to-transform-array-into-textfile – 2011-04-26 08:31:36