By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,277 Members | 1,505 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,277 IT Pros & Developers. It's quick & easy.

Looking for file path of an embedded resource

P: n/a
What class / method should I be using to get the full path to
an embedded resource ? In my case I have an .xml file
that my app uses, it is set as embedded resource, and
I have a control that needs to load it, but I do not want to hard
code the path since that may change for different installs.
i.e. GetPathForResourceOfName ( myResourceFileName )

thanks,

JIM

Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You can't get the filename of an embedded resource because it's embedded!
i.e. The contents of the file is copied into the assembly (DLL or EXE)
during the build process.

- Lee

"james" <no****@hypercon.net> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...
Lee, yes I need the file name with full path

that's why I was thinking of GetPathForResourceOfName (
myResourceFileName )
this would give me the path for a resopurce of some name in my embedded
resources.
My control already has the code to load the file given the name.

thanks,

JIM

"Lee Chapman" <Please Reply To Group> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
Do you want the data in the file or the filename? I use the following to
access the contents of an embedded file:

Stream stream =
Assembly.GetExecutingAssembly().GetManifestResourc eStream(name);

Note that the name needs to include the default namespace for the project. e.g. If the default namespace was My.Namespace and the file with its build action set to "Embedded Resource" was called TextFile1.txt then you'd need to pass "My.Namespace.TextFile1.txt" to GetManifestResourceStream().

You can check what the name to use for a built assembly by loading the
assembly into ildasm.exe, opening the manifest, and looking for the

relevant
.mresource entry.

e.g.
.mresource public My.Namespace.TextFile1.txt
{
}
- Lee
"james" <no****@hypercon.net> wrote in message
news:Of*************@TK2MSFTNGP12.phx.gbl...
What class / method should I be using to get the full path to
an embedded resource ? In my case I have an .xml file
that my app uses, it is set as embedded resource, and
I have a control that needs to load it, but I do not want to hard
code the path since that may change for different installs.
i.e. GetPathForResourceOfName ( myResourceFileName )

thanks,

JIM



Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.