Tools Update: Read Embedded Text Files in Silverlight

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.

About Ashiq Alibhai, PMP

Ashiq has been coding C# since 2005. A desktop, web, and RIA application developer, he's touched ASP.NET MVC, ActiveRecord, Silverlight, NUnit, and all kinds of exciting .NET technologies. He started C# City in order to accelerate his .NET learning.
This entry was posted in Core .NET, Libraries, Silverlight, Wndows Forms and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *