Windows Phone 7帮助 [英] Windows Phone 7 Help
问题描述
我正在制作基于应用程序的IO概念。
1.首先我必须创建新文件并在其中写入一些文字。
2.其次我已经制作了一个阅读文件的按钮。
3.下次我开始这一步。我应该检查出任何文件退出或不存在。如果存在然后阅读,如果没有创建新的。
上面的介绍中的第三件事给我带来了问题。我没有得到如何为此编写代码。如果有任何人知道,请帮帮我。
我开发的读写代码,这里是
I am making an app based IO Concept .
1. First I have to Create New File and write some text in it.
2. Second I have made a button to read a file .
3. Next time when i start with this step . I should check it out that preciously any file exits or not . if exists then read and if not create new.
The 3rd thing in the introduction above is giving me problem . I am not getting how to write code for this . Please Help me if any body knows about it .
Read and Write codes i have developed and here it is
private void btnWrite_Click(object sender, RoutedEventArgs e)
{
// Get the local folder.
System.IO.IsolatedStorage.IsolatedStorageFile local =
System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
// Create a new folder named DataFolder.
if (!local.DirectoryExists("DataFolder"))
local.CreateDirectory("DataFolder");
// Create a new file named DataFile.txt.
using (var isoFileStream =
new System.IO.IsolatedStorage.IsolatedStorageFileStream(
"DataFolder\\DataFile.txt",
System.IO.FileMode.OpenOrCreate,
local))
{
// Write the data from the textbox.
using (var isoFileWriter = new System.IO.StreamWriter(isoFileStream))
{
isoFileWriter.WriteLine(this.textBox1.Text);
}
}
// Update UI.
this.btnWrite.IsEnabled = false;
this.btnRead.IsEnabled = true;
}
private void btnRead_Click(object sender, RoutedEventArgs e)
{
// Obtain a virtual store for the application.
System.IO.IsolatedStorage.IsolatedStorageFile local =
System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
// Specify the file path and options.
using (var isoFileStream =
new System.IO.IsolatedStorage.IsolatedStorageFileStream
("DataFolder\\DataFile.txt", System.IO.FileMode.Open, local))
{
// Read the data.
using (var isoFileReader = new System.IO.StreamReader(isoFileStream))
{
this.textBlock1.Text = isoFileReader.ReadLine();
}
}
// Update UI.
this.btnWrite.IsEnabled = true;
this.btnRead.IsEnabled = false;
}
请尽快帮助。
Please Help as soon you can.
推荐答案
上面的代码很好,您需要添加名称空间使用System.IO;
above code is fine you need to add a namespace "using System.IO;"
这篇关于Windows Phone 7帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!