[ACCEPTED]-Resource from assembly as a stream-embedded-resource

Accepted answer
Score: 36

You're probably looking for Application.GetResourceStream

StreamResourceInfo sri = Application.GetResourceStream(new Uri("Images/foo.png"));
if (sri != null)
{
    using (Stream s = sri.Stream)
    {
        // Do something with the stream...
    }
}

0

Score: 29

GetManifestResourceStream is for traditional 8 .NET resources i.e. those referenced in 7 RESX files. These are not the same as WPF 6 resources i.e. those added with a build 5 action of Resource. To access these you 4 should use Application.GetResourceStream, passing in the appropriate 3 pack: URI. This returns a StreamResourceInfo 2 object, which has a Stream property to access 1 the resource's data.

Score: 8

If I get you right, you have a problem to 5 open the resource stream, because you do 4 not know its exact name? If so, you could 3 use

System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()

to get a list of names of all included 2 resources. This way you can find the resource 1 name that was assignd to your image.

More Related questions