How to share one Insulation Storage for two Windows Forms applications?

I have two applications and a Windows Forms library in one solution.

A library class can create new folders and files in IsolStorage and list all files and folders in IsolStorage.

The first application uses the library class to create new folders / files. I want the second to display the folders created by the first application. How can I get them to use the same isolated storage?

+3
source share
1 answer

Use IsolatedStorageFile.GetUserStoreForAssemblyto create isolated storage from the library.

Details here

. 1 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();
            }
        }
    }

EDIT:

DLL . , . Go to project properties

In the Signing tab of the properties, Click on "New" drop down item and provide a snk name in the dialog

+4

All Articles