Solved

c# included resource file in the code

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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:…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

763 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