-1

I want to output a File from my .NET program. For example a Image to be created in the same folder as the Executable. I want the file to be included in the Program. Is there any way to do this?

1
  • what do you mean exactly, create file programmatically or copy references or something else?
    – VladL
    Feb 24, 2013 at 16:11

1 Answer 1

0

Yes. You can add the file to your project and set it as "Embedded Resource" for compile options under properties. The file will be embedded in the assembly.

You can get the file as a stream from code using:

GetType().Assembly.GetManifestResourceStream(GetType(), "filename.ext");

Here I used GetType as a shortcut to get an instance of the current assembly object. The name will be prefixed by the namespace relative to the type you pass in as the first parameter (so, if the type and the file are in the same folder, you can use the original filename).

2
  • How can embed the File to the program? Because If I just add it and set it as Embedded Resource, the Program file is smaller than the file itself.
    – Horsti
    Feb 24, 2013 at 17:06
  • That's not very helpful. How does it not work ? Do you get an exception ? You need to be sure that the name matches the embedded resource, which can be tricky because you need to take the namespace into consideration.
    – driis
    Feb 24, 2013 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.