保存按鈕的代碼如下:
private void btnSave_Click(object sender, RoutedEventArgs e)
{
string fileContent = this.txtContents.Text;
using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
{
string filePath = System.IO.Path.Combine(@"C:\Users\v-yanjxu\Documents\Visual Studio 2013\Projects", this.txtFileName.Text);
IsolatedStorageFileStream stream = storage.OpenFile(filePath, FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(stream);
sw.Write(fileContent);
sw.Close();
stream.Close();
}
GetStorageData();
}
原本filePath=“File1.txt”;,這樣保存是沒有問題的,可是我要是把filePath改成filePath=System.IO.Path.Combine(@"C:\Users\v-yanjxu\Documents\Visual Studio 2013\Projects", this.txtFileName.Text);時,就會報“Operation not permitted on IsolatedStorageFileStream.”的異常。難道IsolatedStorageFile保存文件時不能指定路徑麼?
獨立存儲是只能將數據存儲到應用的數據區,不能指定位置的,這是系統的限制。