bar*_*anq 3 c# isolatedstorage visual-studio-2010 winforms
我在一个解决方案中有两个 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 应该是一个强命名的程序集。下面的快照显示了如何向程序集添加强名称。


| 归档时间: | 
 | 
| 查看次数: | 2436 次 | 
| 最近记录: |