Just a small reminder for myself. I have to do this way too often recently to remember.
This is how to read embedded resources in Silverlight application (or WPF app for that matter) – like binaries, images, xml, etc, from an embedded resource
/// Reads information from an embedded resource.
/// In VS, set the type of the file in solution explorer to “Embedded Resource”
/// bytes = ReadBytesFromStream(“MyTestProgram.SomeDataFile.xml”)
/// <param name=”streamName”></param>
private byte ReadBytesFromStream(string streamName)
using (System.IO.Stream stream = this.GetType().Assembly.GetManifestResourceStream(streamName))
byte result = new byte[stream.Length];
stream.Read(result, 0, (int) stream.Length);