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