This documentation is archived and is not being maintained.

Code: Retrieving an Image that is an Embedded Resource (Visual C#)

Visual Studio .NET 2003

This example retrieves an image that is an embedded resource of the assembly.


System.Reflection.Assembly thisExe;
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream file = 
this.pictureBox1.Image = Image.FromStream(file);

Compiling the Code

This example requires:

  • A Windows Form with a PictureBox control named pictureBox1.

Add the image file to the project, and set the Build Action property to Embedded Resource in Solution Explorer.

Replace "AssemblyName.ImageFile.jpg" with the name of the resource, as it is known in the assembly. Use the GetManifestResourceNames method of the Assembly object to find the resource name. See Code: Finding the Names of Resources in an Assembly.

Robust Programming

The following conditions may cause an exception:

  • The embedded resource does not exist in the assembly, and the call to GetManifestResourceStream returns Nothing.
  • There may not be an application associated with the file type (the file extension).

See Also

Windows Forms Example Topics | Code: Finding the Names of Resources in an Assembly | Code: Running a Program | Process Class