Hello,

I need the path (string) of an embedded file in a Console application. I tried "Properties.Resource.file", but I got its content, not the path. Any help is appreciated.

Do you mean inclusion files? Like System.Linq, System.IO and such?
They're located in

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft

Microsoft Visual Studio 12.0, on Windows 7 x64, you can make constant variable out of that.

If you need something else, please explain it with more details.

path of an embedded file

Doesn't say much to someone who works with C# and Visual Studio. Or at least, it says not a lot to me.

Hi

It is my understanding that embedded resources are part of your assembly (executable) and therefore the only path is that to your executable. If you want to use the resource, you need to use reflection. Take a look at: How to embed and access resources using C# for more information.

HTH

The file is embedded in your assembly, it has no path. If you want a file you can work with outside of the resource interface, then consider GetManifestResourceStream from the assembly object for a little more control.

Hi Navee30 welcome at DaniWeb!
If you consider that your application executable is like a raisin cake, the resources are the raisins in the dough. They are embedded. Only your app knows how to reach them. There isn't a path to them, only to the application.

commented: Mmmmm... +1

Thanks for the replies.

@ddanbe:
I have a text file (embedded) and I need to load it in a method ReadFile(string path). How could I do?

If this method is part of your app, I guess you don't need a path.

I have a text file (embedded) and I need to load it in a method ReadFile(string path). How could I do?

If you take a look at the link I posted, it contains an example of reading a text file from a resource that is embedded into your assembly using the GetManifestResourceStream that deceptikon mentioned.

@ddanbe
Yes, but it is imperative that the method accepts a path as a parameter.. I cannot change it.

@djjeavons
I read the content of the link you posted, but I still get an error

Yes, but it is imperative that the method accepts a path as a parameter.. I cannot change it.

  1. Get the stream.
  2. Create a file from that stream.
  3. You now have a path.
  4. Profit.

Yes, but it is imperative that the method accepts a path as a parameter.. I cannot change it.

Just adding to deceptikon's post (as I was going to suggest something similar), but if you really can't read it as an embedded resource due to this restriction then why is it embedded in the first place?

Application.StartupPath

Application.StartupPath

Thanks!

please mark this article if you've got what you nee. thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.