Solved

c# included resource file in the code

Posted on 2011-03-25
4
269 Views
Last Modified: 2013-12-17
Hi,

I have a bianry resource that I want included in the code so that nobody see it. How can I do it?

Thanks,
JT
0
Comment
Question by:jtran007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Expert Comment

by:dimaj
ID: 35215675
I believe there's a 'Resources' solution item that you can add (by right-clicking on your project).
0
 
LVL 7

Expert Comment

by:dimaj
ID: 35215687
also, here's an article by Microsoft: http://support.microsoft.com/kb/319292
0
 
LVL 16

Accepted Solution

by:
ToddBeaulieu earned 250 total points
ID: 35216054
Hello,

Simply add the file to the project. You can put it in a project folder if you'd like, but the real trick is to right click the item and select "properties". Next, change the BuildAction to "Embedded Resource".

Finally, you have to access that resource. Here's an example of my code accessing an xml resource.
private string ReadTestData()
        {
            string result = string.Empty;

            //string[] resources = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();

            string resourceName = @"{fullnamespace of assy}.UnitTestData.xml";

            using (System.IO.Stream s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
            {
                using (System.IO.StreamReader sr = new System.IO.StreamReader(s))
                {
                    result = sr.ReadToEnd();
                }
            }

            return result;
        }

Open in new window

0
 

Author Closing Comment

by:jtran007
ID: 35224662
thanks,
jt
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 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