Is there a way to get a string path reference to an embedded resource file?

Viewed 15009

I have a method that takes a string parameter that is a file path to a text file. I want to be able to pass in a text file that I have embedded as a resource in my assembly.

Is there any way to get a string reference to an embedded text file so that it would function as a file path for opening a StreamReader?

Thanks.

3 Answers

One method that worked for my use case was from the following answer: https://stackoverflow.com/a/34664553/11860907

For Binary files: File.WriteAllBytes(outputpath, Properties.Resources.file);

For Text files: File.WriteAllText(outputpath, Properties.Resources.file);

I just ran this line of code for every embedded resource file I needed when my program first opened and it placed the resource files somewhere that I could then reference as a string path.

Related