CodeGuru
Earthweb Search
Login Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

follow us on Twitter

Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















Home >> .NET / C# >> .NET >> General >> Performance


Take Advantage of Isolated Storage with .NET
Rating: none

Mike Amundsen (view profile)
November 3, 2004

Go to page: Prev  1  2  

Testing the IsoStorage Class

Below is a simple console application that gets an instance of the AppItems collection, adds several AppItem objects to the collection, and then stores the collection on disk. Finally, it reads that same collection from the disk and echoes the name/value pairs to the console. The following is the complete code for this test app:

using System;
using amundsen.Utility;

public class IsoConsole
{
    public static void Main()
    {
        AppItems writeItems = new amundsen.Utility.AppItems();
        writeItems.Add(new AppItem("name","mike"));
        writeItems.Add(new AppItem("amount",13.5));
        writeItems.Add(new AppItem("datepaid",System.DateTime.Now));

        amundsen.Utility.IsoStorage iso = new amundsen.Utility.
                 IsoStorage();

        iso.WriteAppCollection("testing.txt",writeItems);

        AppItems readItems = iso.ReadAppCollection("testing.txt");

        for(int i=0;i<readItems.Count;i++)
        {
            AppItem item = (AppItem)readItems[i];
            Console.WriteLine(String.Format("{0}={1}",item.Name,
                                            item.Value));
        }
    }
}

(continued)




Below is the resulting output when you run the above code:


(
Full Size Image)

But where, you might ask, is this information stored on the disk? It depends on which Windows OS you are using and whether it was a fresh install or an upgrade from an older OS. However, clean installs of XP and Windows 2003 store the data in a unique folder name within <SYSTEMDRIVE>\Documents and Settings\<user>\Local Settings\Application Data. They store roaming profiles in a different location. When I ran this example on my machine, the OS stored the testing.txt file in a folder called AssemFiles at this location:

C:\Documents and Settings\MCA\Local Settings\Application Data\IsolatedStorage\i3ltsz13.04j\ybsvcgd0.iwo\Url.jw0fj4okszugu4hi3vglikpjpr4ih0nd

A Safe Place for Your Data

Now you know that .NET provides a safe location for storing application- and user-specific data. You've also learned how to access this isolated storage space and how to build a simple utility class that can easily read and write name/value pairs to it.

About the Author
An internationally known author and lecturer, Mike Amundsen travels throughout the United States and Europe speaking and teaching on a wide range of software-related topics. He has more than a dozen proramming books to his credit. When he is not working, Mike spends time with his wife and three children at their home in Kentucky, USA.

Go to page: Prev  1  2  

Downloads

  • IsoStorageCode.zip - Download the source code - 4 Kb

    Tools:
    Add www.codeguru.com to your favorites
    Add www.codeguru.com to your browser search box
    IE 7 | Firefox 2.0 | Firefox 1.5.x
    Receive news via our XML/RSS feed







  • RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

    (You must be signed in to rank an article. Not a member? Click here to register)

    Latest Comments:
    No Comments Posted.
    Add a Comment:
    Title:
    Comment:
    Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



    (You must be signed in to comment on an article. Not a member? Click here to register)

    internet.commediabistro.comJusttechjobs.comGraphics.com

    Search:

    WebMediaBrands Corporate Info

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs