2

I would like extract an Embedded ressource from my source.

For this i use a compiler :

CompilerParameters CP = new CompilerParameters();
 [...code...]

CP.EmbeddedResources.Add(@"C:\WindowsFormsApp3.exe");

My ressource + the source.txt

Now, i have the ressource in my file : with the ressource

But how i can extract-it? I use this topic : How to Read an embedded resource as array of bytes without writing it to disk? But it's doesnt work, nothing appear in my folder :/

So if you can help me , i want extract the ressource in a folder.

Thanks you.

J.Doe
  • 21
  • 4

1 Answers1

0

When you add existing files to the project using Resources.resx (under Properties) by default the build action will be none. You need to select the file under the resources folder and chnage the build action to Embeded Resource which means it will be included in the assembly or Content which means it won't be included in your assembly.

To get a list of all embeded resources, you can use this:

string[] embededResources = Assembly.GetExecutingAssembly().GetManifestResourceNames();

To use the resources:

//OctoBox: Picturebox
//Octocat: Octocat.png image

//Tested with:
//Build action: Embeded Resource
// 1st:
OctoBox.Image = (Bitmap)Resources.ResourceManager.GetObject("Octocat");

//2nd
Assembly asm = Assembly.GetExecutingAssembly();
Stream octoStream = asm.GetManifestResourceStream($"{asm.GetName().Name}.Resources.Octocat.png");

if (octoStream != null)
{
    OctoBox.Image = Image.FromStream(octoStream);
    octoStream.Close();
}

//Tested with:
//Build action: None, Content and embeded resource
OctoBox.Image = Resources.Octocat;

The last one being the easiest with intellisense.

Vanna
  • 746
  • 1
  • 7
  • 16