I'm sure this has been done before and is probably quite simple to achieve but I can't seem to find anything on the internet when I've searched.
I'm looking for a way to pickup/copy a file from my applications resources and place it into a folder on my the C: drive.
Can this be done? Or should I read in the contents of the file and then create a new one in the desired directory?
Any pointers/advice would be appreciated! Thanks.
Asked
Active
Viewed 147 times
0

Paul Alexander
- 2,686
- 4
- 33
- 69
-
ive certainly seen it done with resource strings, and images... – BugFinder Jul 30 '18 at 11:03
-
https://stackoverflow.com/a/32287201/3110834 – Reza Aghaei Jul 30 '18 at 13:18
2 Answers
1
You can take the contents of the embedded file and write them out to your desired location as follows:
using (var fs = new FileStream(@"C:\Temp\Foo.txt", FileMode.Create))
using (var sw = new StreamWriter(fs))
{
var data = Stuff.Foo;
sw.Write(data);
}
I did this for a text file embedded in Stuff.resx
in my project. There's a Write
overload for various types so you can use what you need. For instance, an image will come back as a bitmap.

Fabulous
- 2,393
- 2
- 20
- 27
0
I achieved this by using File.WriteAllBytes()
Example:
File.WriteAllBytes("C:\\MyApp\\TextExample.json", MyApp.Properties.Resources.TextExample);

Paul Alexander
- 2,686
- 4
- 33
- 69