0

how can i bring my files (located in resources) back to life. This means every time my program launches, it will delete everything in its directory except it self, then extract those files . I want those files to be created in the currentdirectory.

Can u provide a concept how to extract the files in directory. Then delete everything when it the program starts again,

PS: those files end in .ovpn (they are not binary because they can be read in notepad.. how can i make those files .ovpn in the filesystem? Tnx

Lufthansa
  • 145
  • 1
  • 2
  • 12

1 Answers1

1

To get a file compiled as an embedded resource you can do this:

using (var stream = Assembly.GetCallingAssembly()
          .GetManifestResourceStream("Namespace.FileName.Extension"))
{
    // write file...
}

Of course you would need to use the assembly that the resource resides in.

So for a file called 'Help.txt' in namespace 'MyCompany.MyProduct' you would call:

GetManifestResourceStream("MyCompany.MyProduct.Help.txt")

Hope that gets you on your way.

Eben Roux
  • 12,983
  • 2
  • 27
  • 48
  • tnx how can i bring a file in the resources back to life? Tnx. I want it to appear in my filesystem working directory. – Lufthansa Jul 02 '11 at 08:22
  • to write a stream to a file see this Q&A: http://stackoverflow.com/questions/411592/how-do-i-save-a-stream-to-a-file – Eben Roux Jul 02 '11 at 09:26