?
Solved

How do I load a resource from within my app

Posted on 2004-11-12
7
Medium Priority
?
304 Views
Last Modified: 2010-05-18
I am currently using the folowing syntax to load an Image ,
    upimage.FromFile("C:\Report.bmp")
If a add Report.bmp to my application ,how do I reference or load this Image  from within my app?
Cheers
0
Comment
Question by:visualbasic
  • 4
  • 2
7 Comments
 
LVL 14

Expert Comment

by:ptakja
ID: 12564406
Here's what you have to do:

1) Make sure the property "Build Action" is set to "Embedded Resource" for your image file(s). You can see this property by selecting the file in VS and looking at the properties.

2)  To load the file as a resource:

Dim AssyName As String = [Assembly].GetExecutingAssembly.GetName.Name
DIm bmp as New Bitmap = [Assembly].GetExecutingAssembly.GetManifestResourceStream(AssyName & ".Report.bmp")

upimage.Image = bmp

The syntax for the filename in the GetManifestResourceStream method is <assemblyName>.File.extension

Jeff
0
 

Author Comment

by:visualbasic
ID: 12568214
this sugestion does not seem to work ,problem is with
DIm bmp as New Bitmap = [Assembly].GetExecutingAssembly.GetManifestResourceStream(AssyName & ".Report.bmp")

do you have any other sugestions

cheers
0
 
LVL 14

Expert Comment

by:ptakja
ID: 12568517
Do you have the line above it in your code? AND did you follow Step 1 in my original post? I have 2 applications with embedded image resources that work just fine using this exact code (except for the file name) on both the full .NET Framework as well as the Compact Framework.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 14

Expert Comment

by:ptakja
ID: 12568534
Whoops...wrong syntax. Try this:

 Comment from ptakja
Date: 11/12/2004 06:36AM EST
 Your Comment  


Here's what you have to do:

1) Make sure the property "Build Action" is set to "Embedded Resource" for your image file(s). You can see this property by selecting the file in VS and looking at the properties.

2)  To load the file as a resource:

Dim AssyName As String = [Assembly].GetExecutingAssembly.GetName.Name
DIm bmp as New Bitmap = [Assembly].GetExecutingAssembly.GetManifestResourceStream(AssyName & ".Report.bmp")

upimage.Image = bmp

The syntax for the filename in the GetManifestResourceStream method is <assemblyName>.File.extension

Jeff
 
Comment from visualbasic
Date: 11/12/2004 12:46PM EST
 Author Comment  


this sugestion does not seem to work ,problem is with
DIm bmp as New Bitmap([Assembly].GetExecutingAssembly.GetManifestResourceStream(AssyName & ".Report.bmp"))
 
 Sorry about that! :-|
0
 
LVL 14

Accepted Solution

by:
ptakja earned 200 total points
ID: 12568541
Aghhh. this is how my day is going!

Dim bmp as New Bitmap([Assembly].GetExecutingAssembly.GetManifestResourceStream(AssyName & ".Report.bmp"))


0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12570939
What is the Build Action property set to for the embedded file in the assembly?  Is it Compile, Content, or Embedded Resource?  Are you getting any errors?

Bob
0
 

Author Comment

by:visualbasic
ID: 12572912
thanks a million ptakja  ,that worked a treat!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question