If you mean a simply a file marked as an embedded resource, then the
following shows both stream and reader usage. For files in a resx, it is
harder; text files get handled as strings by default... I've never
bothered finding out if you can change this ;-p
Marc
using System;
using System.IO;
using System.Reflecti on;
class Program
{
static void Main()
{
// need to start at an assembly (and optionally, also a Type)
Assembly assembly = typeof(Program) .Assembly;
// what do we have access to?
foreach(string name in assembly.GetMan ifestResourceNa mes()) {
Console.WriteLi ne(name);
}
// watch for the default namespace!
const string FOO_NAME = "MyDefaultNames pace.foo.xml";
// open the stream-reader
using(StreamRea der reader = new StreamReader(
assembly.GetMan ifestResourceSt ream(FOO_NAME)) ) {
Well, what does the first loop display? And are you sure it is an
embedded resource? If it is just "a resource on the file system" then
you can just use File.Open etc... "resource" is an overloaded term, so I
guessed at "embedded".
That is the "resx" I was referring to... text contents have this
distressing tendency to jump into strings ;-(
You could look at ResourceManager .GetStream, but I've never managed to
get it working (meaning: I was happy to simply use an embedded resource
instead...)
Comment