Windows手机将数据保存到文件

时间:2014-07-07 20:57:53

标签: c# windows windows-phone-7

我已尝试将数据保存到文件但我收到了以下错误 第Operation not permitted on IsolatedStorageFileStream行<{1}}

IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(path, FileMode.OpenOrCreate, storage);

1 个答案:

答案 0 :(得分:2)

试试这个:

public void SaveFile(string path, string data)
{
    using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (var fileStream = new IsolatedStorageFileStream(path + fileName, FileMode.Create, FileAccess.Write, storage))
        {
            using (StreamWriter writer = new StreamWriter(fileStream))
            {
                writer.WriteLine(data);
                writer.Close();
            }
            fileStream.Close();
        }
    }
}