岁月静好_cai 2015-04-01 09:53 采纳率: 75%
浏览 2089
已采纳

Silverlight中通过独立存储,怎么将文件保存到指定路径下?

保存按钮的代码如下:

 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保存文件时不能指定路径么?

  • 写回答

2条回答 默认 最新

  • 普通网友 领域专家: 编程技术技术领域 2015-04-01 10:16
    关注

    独立存储是只能将数据存储到应用的数据区,不能指定位置的,这是系统的限制。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?