Solved

c# included resource file in the code

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

839 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