• RV
    • Missy – My Home
    • JBAM – Newmar Dutch Star
    • Shaneeda
    • Buying a Used RV
    • Gas vs Diesel RVs
    • Ideal Motorhome
    • Choosing the Ideal RV
  • Cycling
  • Jeep
  • About
  • Flying
    • Vans RV-4
    • Daisy – RV-3B
  • Resources
  • Subscribe

JdFinley.com

Fulltime RV Living Adventures

  • Is Solar For You?
  • Gas vs Diesel RVs
  • Buying a Used RV
  • Choosing the Ideal RV
  • Ideal Motorhome

Isolated Storage

June 29, 2011

Isolated Storage is a slick little feature available to Microsoft .Net Windows applications and services. It allows a VB.Net or C#.Net assembly to persist some piece of information to a protected location on disk. This information can be a serialized object, a string, a date, or whatever.  I use Isolated Storage fairly regularly in Services to store progress information or startup information.  I usually keep startup/configuration information in the database but frequently the services must be able to start even when the database is not available.  I first attempt to retrieve the information from the database and if unable, read the last good data from Isolated Storage. When the database access is successful, I write the current information to Isolated Storage so the most recent data is always available.

You will need to import/use the .Net System.IO and .Net System.IO.IsolatedStorage namespaces.

The following code will write the data to a location to which only the current user or assembly has permission:

            Dim _isolatedStorageStore As IsolatedStorageFile

            _isolatedStorageStore = IsolatedStorageFile.GetStore(
                 IsolatedStorageScope.User Or IsolatedStorageScope.Assembly,
                 Nothing, Nothing)

            Dim _streamWriter As New StreamWriter(
               New IsolatedStorageFileStream("File/Store Name",
               FileMode.OpenOrCreate, _isolatedStorageStore))

            _streamWriter.WriteLine(lString)
             _streamWriter.Close()

Reading the contents of the file is just the reverse:

            Dim _isolatedStorageStore As IsolatedStorageFile
            _isolatedStorageStore = IsolatedStorageFile.GetStore(
                IsolatedStorageScope.User Or IsolatedStorageScope.Assembly,
                Nothing, Nothing)
            Dim _streamReader As New StreamReader(
                    New IsolatedStorageFileStream("File/Store Name",
                    FileMode.Open, _isolatedStorageStore))

            Dim _fileContents As String
            _fileContents = _streamReader.ReadLine

            _streamReader.Close()

Note that reading the contents back can be more complicated depending on what you have written into the file.  You may need to use something other than the StreamReader ReadLine routine to retrieve the full contents.

The following code will delete the file that you have created:

        _isolatedStorageStore.DeleteFile("File/Store Name")

There are many, many uses for Isolated storage.  Storing a user’s preferences, last selection, history, etc… are all possibilities.

(Visited 128 times, 1 visits today)

Related posts:

Default ThumbnailObject Serialization (binary) Default ThumbnailXML Serialization Default ThumbnailCompare Date Values Default ThumbnailSo you want to be a Developer?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Have a heart that never hardens, a temper that never tires, a touch that never hurts.

— Charles Dickens

Popular Posts

  • Powermatic Model 90 Wood Lathe & VFD
  • Wood Turning on a Lathe
  • Chainsaw Review: Sportsman 20 in. 52cc
  • Cielo Grande Barbed Wire Fence Repair

Email Notification


 

Posts by Subject

3DPrinting Aircraft Airstrip Bible Bus bus boys Camping Cat Computers Cycling Development Electrical electronics Entertainment Environment Factory Five family FAQ Finances flying Food God Health Holiday Home Humor kayak Life Maintenance Nature Photography Review RV-3 RV-4 sailboat sailing self improvement Sewing solar Travel Video weather wood woodworking X-Country

Posts by Month

© Copyright © 2025 JDFinley.com · All Rights Reserved · Privacy Policy

Unauthorized use and/or duplication of this material without express and written permission from this site’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to JD Finley and JdFinley.com with appropriate and specific direction to the original content.