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

Loading Embedded Resources

P: n/a
I currently have an RTF file added to my project as an embedded resource.

I am then using the following code to read it into a richtextbox:

Stream stream =
this.GetType().Assembly.GetManifestResourceStream( "DKPCalc.doc.rtf");

if (stream != null) {
StreamReader sr = new StreamReader(stream);
richTextBox1.LoadFile(stream, RichTextBoxStreamType.RichText);
sr.Close();
}else
MessageBox.Show("Could not load resource.");

Whenever I try to use this, 'stream' is returned as a NULL.

do a:

Stream stream =
this.GetType().Assembly.GetManifestResourceStream( "Resources/doc.rtf");

the text will be loaded in debug mode but of course fails when the app is
distributed because I don't distribute the rtf..

I have read several whitepapers on MSDN and have tried
http://msdn.microsoft.com/library/de...classtopic.asp
but have met no success.

Any help would be appreciated.
Jul 23 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
It seems that you haven't included app's namespace in resource name. Do so, I
think it must be the solution.
--
cheers
farshad

Jul 23 '06 #2

P: n/a
The namespoace is called DKPCalc
the filename is doc.rtf

Do I have this entered incorrectly?

Stream stream =
this.GetType().Assembly.GetManifestResourceStream( "DKPCalc.doc.rtf");

"farshad.A" <fa******@discussions.microsoft.comwrote in message
news:AE**********************************@microsof t.com...
It seems that you haven't included app's namespace in resource name. Do
so, I
think it must be the solution.
--
cheers
farshad

Jul 23 '06 #3

P: n/a
Ryan,
I tried your code(except with my own namespace and filename:
"windowsapplication2.my.rtf") with absolutely no error. maybe you are not
using the correct case of letters, since the resource name is case-sensitive.
--
cheers
farshad
Jul 24 '06 #4

P: n/a
Ryan,

If you are still having problems, I'd suggest downloading a tool like dotnet
Reflector

(freely available here : http://www.aisto.com/roeder/dotnet/ )

You could then load your assembly into Reflector, then see if the embedded
resource is really there, and confirm the full namespace path of the
resource.

HTH,
Stephen
"Ryan Ramsey" <ry********@yahoo.comwrote in message
news:eo******************************@adelphia.com ...
I currently have an RTF file added to my project as an embedded resource.

I am then using the following code to read it into a richtextbox:

Stream stream =
this.GetType().Assembly.GetManifestResourceStream( "DKPCalc.doc.rtf");

if (stream != null) {
StreamReader sr = new StreamReader(stream);
richTextBox1.LoadFile(stream, RichTextBoxStreamType.RichText);
sr.Close();
}else
MessageBox.Show("Could not load resource.");

Whenever I try to use this, 'stream' is returned as a NULL.

do a:

Stream stream =
this.GetType().Assembly.GetManifestResourceStream( "Resources/doc.rtf");

Jul 24 '06 #5

P: n/a
This helped TREMENDOUSLY....

It turns out that I didn't have "Resources" in the string.
Stream stream =
this.GetType().Assembly.GetManifestResourceStream( "DKPCalc.Resources.doc.rtf");

"Stephen Ahn" <noaddresswrote in message
news:ec**************@TK2MSFTNGP04.phx.gbl...
Ryan,

If you are still having problems, I'd suggest downloading a tool like
dotnet
Reflector

(freely available here : http://www.aisto.com/roeder/dotnet/ )

You could then load your assembly into Reflector, then see if the embedded
resource is really there, and confirm the full namespace path of the
resource.

HTH,
Stephen
"Ryan Ramsey" <ry********@yahoo.comwrote in message
news:eo******************************@adelphia.com ...
>I currently have an RTF file added to my project as an embedded resource.

I am then using the following code to read it into a richtextbox:

Stream stream =
this.GetType().Assembly.GetManifestResourceStream ("DKPCalc.doc.rtf");

if (stream != null) {
StreamReader sr = new StreamReader(stream);
richTextBox1.LoadFile(stream, RichTextBoxStreamType.RichText);
sr.Close();
}else
MessageBox.Show("Could not load resource.");

Whenever I try to use this, 'stream' is returned as a NULL.

do a:

Stream stream =
this.GetType().Assembly.GetManifestResourceStream ("Resources/doc.rtf");


Jul 24 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.