【问题标题】:IsolatedStorageSettings missing assembly隔离存储设置缺少程序集
【发布时间】:2013-11-30 00:06:18
【问题描述】:

我正在尝试使用 IsolatedStorageSettings 在我的 Windows 窗体应用程序中保存一些与设置相关的数据。但是,一旦我创建了该类的实例,我就会收到一条错误消息,指出命名空间中不存在 IsolatedStorageSettings。这是我的代码:

using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using System.IO.IsolatedStorage;

namespace HangedGame
{
public partial class Form1 : Form
{
    string word;
    string foundWord;
    int count;
    private System.IO.IsolatedStorage.IsolatedStorageSettings appSettings =
        IsolatedStorageSettings.ApplicationSettings;
}
}

这是怎么回事?

【问题讨论】:

  • 在winform应用程序中不能使用isolatedstorage,孤立stroage可以在windows phone或windows metro风格的应用程序中使用。您可以轻松地将数据存储在 winform 应用程序、xml 或任何 sql server 的内存中
  • @AOZ 我实际上来自 Mac 开发背景,所以我对 c# 或 winforms 不太熟悉。 c# 中的 NSUserSettings 相当于什么?
  • NSUserSettings ~= IsolatedStorage :) 在 windows phone 和 Metro 风格的应用程序中。但我想你必须使用 xml 或数据库来保存用户数据。您应该使用 db (ado.net) 或实体框架进行搜索。在.Net中使用db非常简单

标签: c# winforms settings


【解决方案1】:

试试这个,

Creating a Folder and File under IsolatedStorage

using (IsolatedStorageFile storage = IsolatedStorageFile.GetStore((IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly | IsolatedStorageScope.User), null, null))
{
    storage.CreateDirectory(@"SampleStorageFolder");
    storage.CreateFile(@"SampleStorageFolder\ReadMe.txt");
}

Reading File created under IsolatedStorage

using (IsolatedStorageFile storage = IsolatedStorageFile.GetStore((IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly | IsolatedStorageScope.User), null, null))
{
   using (StreamReader reader = new StreamReader(storage.OpenFile("ReadMe.txt", FileMode.Open)))
    {
       string content = reader.ReadToEnd();
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多