Solved

c# included resource file in the code

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now