如何为两个Windows窗体应用程序共享一个IsolatedStorage?

我在一个解决方案中有两个Windows窗体应用程序和库。

库类可以在IsolatedStorage中创建新文件夹和文件,并列出IsolatedStorage中的所有文件和文件夹。

第一个应用程序使用库类创建新文件夹/文件我希望第二个应用程序列出第一个应用程序创建的文件夹。 如何让他们使用相同的隔离存储?

使用IsolatedStorageFile.GetUserStoreForAssembly从库中创建独立存储。

细节在这里

您可以在库中使用以下类型。 application1和application2可以通过库中的以下类型对同一个隔离存储进行写入/读取。

下面:

  public class UserSettingsManager { private IsolatedStorageFile isolatedStorage; private readonly String applicationDirectory; private readonly String settingsFilePath; public UserSettingsManager() { this.isolatedStorage = IsolatedStorageFile.GetMachineStoreForAssembly(); this.applicationDirectory = "UserSettingsDirectory"; this.settingsFilePath = String.Format("{0}\\settings.xml", this.applicationDirectory); } public Boolean WriteSettingsData(String content) { if (this.isolatedStorage == null) { return false; } if (! this.isolatedStorage.DirectoryExists(this.applicationDirectory)) { this.isolatedStorage.CreateDirectory(this.applicationDirectory); } using (IsolatedStorageFileStream fileStream = this.isolatedStorage.OpenFile(this.settingsFilePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)) using (StreamWriter streamWriter = new StreamWriter(fileStream)) { streamWriter.Write(content); } return true; } public String GetSettingsData() { if (this.isolatedStorage == null) { return String.Empty; } using(IsolatedStorageFileStream fileStream = this.isolatedStorage.OpenFile(this.settingsFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)) using(StreamReader streamReader = new StreamReader(fileStream)) { return streamReader.ReadToEnd(); } } } 

编辑:

该DLL应该是一个强名称的程序集。 下面的快照显示了如何向程序集添加强名称。 转到项目属性

在属性的“签名”选项卡中,单击“新建”下拉项并在对话框中提供snk名称