Get the path of a resource c #

0

I have the following resource included to my project:

Is there any possible way to get the resource path or an alias to call it?

Since it is essential that you can know the route or alias of the resource to be able to use it, for example in the function that will call this resource.

Funcion(string ruta,string argumento)

In my case I will read the resource and then do a series of things:

private static void Funcion(string ruta, string argumento){
//existe la ruta
if (!File.Exists(ruta))
                return;
//leeme el fichero
byte[] resourcesBuffer = File.ReadAllBytes(ruta);
/*etc*/
}

How could I get the route or is it impossible to use a resource included in my project?

    
asked by Sergio Ramos 01.04.2017 в 02:17
source

1 answer

1

The first point I can make is that you do not embed an object from the \ bin \ Debug folder, it's a bad idea. Copy the file and place it inside the project, in a different route.

Also, you do not need a resx so that the file is linked to the code you compile, you could include it in the project and use the option Build Action

An embedded resource does not have a physical path, unless you extract the file, as explained here

Saving an embedded file in C #

You access the assembly stream

Assembly.GetExecutingAssembly().GetManifestResourceStream()

to save it in a temporary folder and thus be able to execute it. You will always be able to recover it in this way when you need it.

    
answered by 01.04.2017 / 02:32
source