Use an Isolated Store - CSharp File IO

CSharp examples for File IO:Isolated Storage

Introduction

IsolatedStorageFile and IsolatedStorageFileStream classes can write data to a file in a user-specific directory without needing permission to access the local hard drive directly.

Demo Code


using System;//from  ww  w.  j a v a2  s.  co m
using System.IO;
using System.IO.IsolatedStorage;

    static class MainClass
    {
        static void Main()
        {
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly())
            {
                store.CreateDirectory("MyFolder");
                using (Stream fs = new IsolatedStorageFileStream("MyFile.txt", FileMode.Create, store))
                {
                    StreamWriter w = new StreamWriter(fs);
                    w.WriteLine("Test");
                    w.Flush();
                }
                Console.WriteLine("Current size: " + store.UsedSize.ToString());
                Console.WriteLine("Scope: " + store.Scope.ToString());

                Console.WriteLine("Contained files include:");
                string[] files = store.GetFileNames("*.*");
                foreach (string file in files)
                {
                    Console.WriteLine(file);
                }
            }
        }
    }

Result


Related Tutorials