Get relative path to linked resource in C #

I have a number of related resources (text files in this case) in a C # project I'm working on. I know that resources are linked through a relative path in the Resources file. Is there a way to get this relative path from C # code?

If this does not happen, I try to pass this resource file to an external application as a command line argument. If I could not do it in the first way (which, obviously, would be the easiest), any other suggestions would be highly appreciated. Thank!

+3
source share
3 answers

dll. , , . , Hueso .

, , , BuildAction Content Copy to Output Directory Copy if newer, Copy always. . , .

Edit:

.:

+1

, , , , :

var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var stream = assembly.GetManifestResourceStream("Resources.yourFile.txt");
var tempPath = Path.GetTempPath();
File.Save(stream, tempPath);

// use your tempPath here
0

These three lines take your resource file and output it to a byte array, and then write it to a file on disk.

byte[] byteArray = new byte[Project.Properties.Resources.File.Length];
Project.Properties.Resources.File.CopyTo(byteArray, 0);

File.WriteAllBytes("Filepath", byteArray);
0
source

Source: https://habr.com/ru/post/1738816/


All Articles