Search code examples
c#filestreamisolatedstorage

How to convert isolated memory into File Storage in C#?


Is there anyway to convert Isolated memory to File Storage. I need a method that can get data from Isolated Storage and then Store it to Files that I have already defined in my program.


Solution

  • Following example shows how you could read a text file within IsolatedStorage and write to a specific location,

    string fileContent = string.Empty;
    
    //Read file within 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)))
        {
           fileContent = reader.ReadToEnd();
        }
    }
    
    //Write to a textfile
    File.WriteAllText(@"File path", fileContent);