Answer the question
In order to leave comments, you need to log in
How to read file bytes from resources (C#)?
I compile software using CodeDomCompiler, and add the file to the resources of this software. But I don't know how to read this resource file. I tried like this:
byte[] fat = Properties.Resources.NameProg;
But nothing worked. It was written that Properties was not found.
PS file in resources - exe
Help please, tried all methods :((
Answer the question
In order to leave comments, you need to log in
Save binary from resources to disk:
File.WriteAllBytes(@"C:\NameProg.exe", ProjectName.Properties.Resources.NameProg);
or like this:
File.WriteAllBytes(@"C:\NameProg.exe", Resources.NameProg);
if at the top there is:
using ProjectName.Properties;
where:
ProjectName - the name of your project;
Keep in mind that:
- There can be multiple resource files in a project. In the example above, the data is taken from "Resources";
- to write to some folders, you need to run the program with administrator rights;
- antiviruses can work and delete freshly created exe.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question