Sometimes, your application may need to save the user state or progress for various purposes. Rather than storing the information to server, both technology provided a very convenient way to store some temporary data into user computer.
However, the storage has it own limit size for security reason.
Comparison
Flash implementation: 30 minutes
Silverlight implementation: 2 hours (Implemented First)
What’s the difference?
- flash.net.SharedObject [AS3] vs System.IO.IsolatedStorage.IsolatedStorageFile [C#]
Default local storage limit
- Flash: 100 KB (Can be adjusted to unlimited by user)
- Silverlight: 1024 KB
Source codes
Local Storage [Flash 9, AS3] (8.7 KiB, 630 hits)
Local Storage [Silverlight 2, C#] (30.7 KiB, 761 hits)
Flash
Silverlight
flash.net.SharedObject [AS3] vs System.IO.IsolatedStorage.IsolatedStorageFile [C#]
Using Local Storage is pretty easy in Flash. It’s because you only have to deal with the shared data as if local Object.
Please note that you have to call the flush() method after updating the object. Just to make sure it is saved into file system.
// AS3
// get the shared object
var so: SharedObject = SharedObject.getLocal(OBJECT_NAME);
// load data from local storage
if(so.data.text){
TextArea.text = so.data.text;
}
// save data to local storage
so.data.text = "New Text";
so.data.flush();
In Silverlight, the local storage is actually a predefined path of storage directory. You can read and save data as if reading and writing files.
// C#
// load data from local storage
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
if(store.FileExists(FILENAME)){
isfs = new IsolatedStorageFileStream(FILENAME, FileMode.OpenOrCreate, store);
StreamReader streamReader = new StreamReader(isfs);
string s;
while ((s = streamReader.ReadLine()) != null)
TextArea.Text += (s + '\n');
streamReader.Close();
}
// save data to local storage
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(FILENAME, FileMode.OpenOrCreate, store);
StreamWriter streamWriter = new StreamWriter(isfs);
streamWriter.Write("New Text");
streamWriter.Flush();
streamWriter.Close();

December 1st, 2008 at 3:00 pm
Silverlight has an IsolatedStorageSettings class that is similar to Flash’s SharedObject. It can be used to easily store objects in isolated storage without having to use the lower-level file-based APIs. Using it would look like this:
var settings = IsolatedStorageSettings.ApplicationSettings;
// load data from local storage
string text;
if (settings.TryGetValue(OBJECT_NAME, out text)) {
TextArea.Text = text;
}
// save data to local storage
settings[OBJECT_NAME] = “New Text”;
settings.Save();
Hope this helps!
Regards,
Justin Van Patten
Program Manager
Microsoft
December 1st, 2008 at 4:18 pm
Thanks, that helps.
Acutally, there aren’t much reference on IsolatedStorage and I used a stupid method.
Thanks anyway.
December 1st, 2008 at 4:53 pm
[...] mal zeigt der Vergleich zwischen Silverlight und Flash die lokale Speicherung. Auffallend dabei ist das lokale [...]
December 1st, 2008 at 5:14 pm
I can’t seem to paste a large chunk of text into the Silverlight version, is that a bug with the code you’ve written? It seems to work ok with the Flash version. I voted for the Flash version because of that but I’m not sure what caused the problem.
December 1st, 2008 at 5:19 pm
Hi Terence. Don’t worry about it, you’re method still gets the job done. You can find out more about isolated storage here: http://msdn.microsoft.com/en-us/library/bdts8hk0(vs.95).aspx
I should also mention that if you want to use the lower-level isolated storage APIs instead of IsolatedStorageSettings (as you do above), you can simplify the code a bit as follows:
// C#
// load data from local storage
using (var store = IsolatedStorageFile.GetUserStoreForApplication()) {
if (store.FileExists(FILENAME)) {
using (var stream = store.OpenFile(FILENAME, FileMode.Open))
using (var reader = new StreamReader(stream)) {
TextArea.Text = reader.ReadToEnd();
}
}
}
// save data to local storage
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = store.OpenFile(FILENAME, FileMode.OpenOrCreate))
using (var writer = new StreamWriter(stream)) {
writer.Write(”New Text”);
}
Cheers,
Justin Van Patten
Program Manager
Microsoft
December 1st, 2008 at 5:33 pm
How large is the chunk of text you placed?
I have placed about 100 lines of text and it is working quite well for me.
December 1st, 2008 at 5:46 pm
Hi,
The default size limit with IsolatedStorage is 1MO. But, if your reach the limit, Silverlight prompts you to increase the size.
December 1st, 2008 at 8:33 pm
For Silverlight.
In addition to maximelamure response. You can programmatically set the size for the IsolatedStorage on a users computer but must be done through a specific event like a button click (can’t do it onload of the app), this will then propmt the user to accept the change in size for the Isolated storage. This means that if you have a large business app that needs to save alot of info to IS you can just have the size increased to what you think the max will be.
December 2nd, 2008 at 7:55 am
Silverlight version throws exception for me.
December 2nd, 2008 at 5:45 pm
Your Silverlight application always prompts me to install Silverlight in Firefox (3.0.4), but actually I have installed the Silverlight Plugin (2.0.31005.0).
December 3rd, 2008 at 1:50 am
Huson, thx for reporting the problem. However, I think I have to report this to Microsoft as well.
December 3rd, 2008 at 4:35 pm
It was all the text from a random page I had open in another tab. I went back and checked, it’s just under 5,000 words.
January 6th, 2009 at 10:13 pm
[...] Silverlight vs Flash: Local Storage [...]
June 8th, 2009 at 1:32 am
AcceptsReturn=”True” should be set on the silverlight text box to allow multi line mode. this is probably why you can’t paste in a large block of text.
August 13th, 2009 at 6:36 pm
I started out with audio problems with flash that have continued thru test of silverlight / I’ve tried everything I am ready to give up. It started a few years ago I dropped one thousand dollars on a used sony vio with what I was told would be decent software to use for audio recording and files
which I did not find use in and the program which slips me for the moment appeared more for video and not audio however I liked the new windows xp home for about a little over a year where
the motherboard dropped dead so I was told.
Since then I am working with recycled throw away parts I find in the college town I live in I am fortuned to find lots of desktop throw aways that I’ve managed to get on line with but I don’t know why BUT I HAVE HAD THE WORST LUCK ENABLING AUDIO FUNCTIONS , i AM A 54 year old
electrician and I have been around the world a few times working for years overseas on high voltage installations remodeling and new construction of power plants in micronesia on many different islands. Yet I feel like I have put more effort in attempting to make the audio system
work. I play guitar and keyboards and I’ve to enable my synthsiser up since becomming aware
of the system but I’d settle for just to hear the audio on flash or any other application
I want to say again I have gone through troubleshooting procedures and a thousand other back and forth actions until I am blue in the face and sadly I am not exaggerating
August 13th, 2009 at 6:43 pm
in conj. it could be faulty equipment one action was every time I’d enter a sound scheme it’d
disappear in a faded appearance when I’d restart to see if events improved.
August 14th, 2009 at 3:35 am
HI Quentin, anything I could help related to the topic?
You may find out a more organized code in saving file to LocalStorage here:
http://silverlight.shinedraw.com/#/item/4a76e8ba4b36e