There’s an exciting new version of the Tools library version. Among other things, it includes a class that allows you to read from an embedded text file in your Silverlight application.
Have you ever run into a scenario that you had a lot of data that you wanted to read in during execution of a Silverlight app? Or maybe you want to move some content out of code and into a file, since it belongs there. I know I have — for Valence, the Silverlight chemistry game I’m working on, I have grid definitions of up to 10×10 atoms, plus a smattering of other atoms; instead of a huge array of text, I’d like to stick these definitions in a file and load them at runtime.
Now you can — using the spiffy new EmbeddedResourceFileReader class. All the details are available on the Tools page, so pop over and have a look. The code looks like this:
EmbeddedResourceFileReader.ProjectName = "DeenGames.Valence";
string content = EmbeddedResourceFileReader.ReadFile("Puzzle01.txt");
What’s that, you say? You want to write content too? Maybe do some complex querying on collections of objects? Well, that requires a database; and that will be our next post — how to use a lightweight, client-side embedded Silverlight database in your applications.