Using isolated storage for application-specific data in C# .NET Part 3: storage location

In this post we looked briefly at how to work with directories in isolated storage. In this post we’ll look at where isolated storage files are saved on disk depending on the isolation type: by user or by machine.

Recall our code to save the program settings specifically for the user:

private static void SaveSettingsInIsoStorage()
{
	IsolatedStorageFile applicationStorageFileForUser = IsolatedStorageFile.GetUserStoreForAssembly();
	long quotaInBytes = applicationStorageFileForUser.Quota;
	string[] directoryNames = applicationStorageFileForUser.GetDirectoryNames("AppSettings");
	if (!directoryNames.Any())
	{
		applicationStorageFileForUser.CreateDirectory("AppSettings");
	}
	IsolatedStorageFileStream applicationStorageStreamForUser = new IsolatedStorageFileStream("AppSettings/settings.txt", FileMode.Create, applicationStorageFileForUser);
	AppSettings settings = new AppSettings()
	{
		Job = "Programmer",
		Language = "C#",
		Name = "Andras"
	};
	string contents = JsonConvert.SerializeObject(settings);

	using (StreamWriter sw = new StreamWriter(applicationStorageStreamForUser))
	{
		sw.WriteLine(contents);
	}
}

There’s no property that lets you easily read the actual location on disk. You’ll need to set a breakpoint right after this line:

private static void SaveSettingsInIsoStorage()
{
	IsolatedStorageFile applicationStorageFileForUser = IsolatedStorageFile.GetUserStoreForAssembly();
...
}

When the code execution stops hover over “applicationStorageFileForUser” and open the “Non-public members” section. You’ll see a property called RootDirectory in the bottom of the list. The value should point to a user-specific location. In my case it is…

C:\Users\andras.nemes\AppData\Local\IsolatedStorage\nq213l1g.ul1\tflubnij.chu\Url.2ekkfnx05wuhzecg5x4y0q3tfifmqex4\AssemFiles\

…and there it is:

Isolated storage file location for user

Let’s change the code so that we save the settings at the machine level:

private static void SaveSettingsInIsoStorage()
{	
       IsolatedStorageFile assemblyStorageFileForMachine = IsolatedStorageFile.GetMachineStoreForAssembly();
...
}

The same hidden RootDirectory property will point to the ProgramData folder similar to the following:

C:\ProgramData\IsolatedStorage\ofau1sef.fzp\lchabgk0.ywi\Url.2ekkfnx05wuhzecg5x4y0q3tfifmqex4\AssemFiles\

Let’s check:

Isolated storage file location for machine

Read the finishing part here.

Read all posts dedicated to file I/O here.

Advertisements

About Andras Nemes
I'm a .NET/Java developer living and working in Stockholm, Sweden.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

ultimatemindsettoday

A great WordPress.com site

Elliot Balynn's Blog

A directory of wonderful thoughts

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT TUTORIALS WITH OPEN-SOURCE PROJECTS

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: