Solved

c# included resource file in the code

Posted on 2011-03-25
4
263 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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