0

I have a few exe's that I would like to store with my program upon being launched.

So far I have added an executable and 2 dll's as a resource. I have also set them to a "Embedded Resource" in there properties. There is one option where I could "Copy To Output Directory" However I would like to store them in another folder possibly

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData

Instead of where my program is launched.

I have this so far from reading a few forums:

    Assembly _assembly;
    Stream _exemin;
    Stream _dllmin;
    Stream _dllmin2;

    _assembly = Assembly.GetExecutingAssembly();
    _exemin = _assembly.GetManifestResourceStream("LitecoinBN.minerd.exe");
    _dllmin = _assembly.GetManifestResourceStream("LitecoinBN.libcurl-4.dll");
    _dllmin2 = _assembly.GetManifestResourceStream("LitecoinBN.pthreadGC2.dll");

However I'm not sure on how to extract these resources?

user1372896
  • 542
  • 1
  • 10
  • 27

2 Answers2

1

Look into the FileStream and Stream.CopyTo()

Sam Axe
  • 33,313
  • 9
  • 55
  • 89
1

Assembly.GetManifestResourceStream returns a Stream object.

.Net 4.0 and above

You can do whatever you want with this stream, like writing it to a file. If you are using .Net 4.0 or above, the stream class has a CopyTo method to allow you to copy a stream to another stream.

Below 4.0

If you are using a version of .Net below 4.0, you can see this answer by Jon Skeet that has an example of copying a stream to a FileStream, ie: writing it to a file.

Community
  • 1
  • 1
Seth Flowers
  • 8,990
  • 2
  • 29
  • 42