473,509 Members | 2,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loading Embedded Resources

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
5 14858
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
761
by: Philipp Seidel | last post by:
Hi there! I did not know, where this topic fits in, so I put it here. I have a minor problem with embedded resources, which puzzles me quite a lot. I'd be glad if anyone can help me on this: ...
5
8196
by: Drew | last post by:
Assembly asm = Assembly.GetExecutingAssembly(); me = new Bitmap(asm.GetManifestResourceStream("me.gif")); I have used this before without any problem, but now I get: An unhandled exception...
7
19217
by: Christofer Dutz | last post by:
Hi, I am trying to read a XML-File which I marked as embedded resource from within the code of my DLL. Unfortunately it doesn't work. On my search for the error I inserted some code for...
7
5388
by: Wysiwyg | last post by:
Is there any way to add an embedded resource to a project without copying it to the project's directory? I have shared resources and don't want each project using the images, xml files, etc. to...
4
2132
by: Phil Da Lick! | last post by:
Hello, Got strings.resx included in my assmebly as the default language neutral collection. ResourceManager res=new ResourceManager("strings", Assembly.GetExecutingAssembly()); string...
0
2180
by: Johann Blake | last post by:
I'm having trouble grasping how ASP.NET correctly locates resources. There is plenty of documentation on this subject but some things are not clear at all. In my ASP.NET application, I have...
0
2307
by: npthomson | last post by:
Hi all, This could get a bit complicated but I'll try to be as clear as possible. I've written an application that discovers plugins at runtime using reflection from a subdirectory of the...
8
12054
by: John Dunn | last post by:
Since currently we aren't allowed to have compiled XAML files embedded in C++ apps I'm using Markup::XamlReader::Load to dynamically load XAML files. This works perfectly fine with external files...
0
1695
by: AndySummers | last post by:
Hi We have just re-written a majour asp.net project to use a user control embedded in a web page. The main dll references 3 other custom controls and so to deploy the project I copy the 4 dll's to...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.