‪How to read Embedded Resource in c#

As you may know enterprise applications Embedd all of indeed resources into their assembly because of end users relief and prevention of loosing indeed files, in most cases embedding and using an embedd resource is so easy in dot net (c#) but if you embedd an xml resource and want to read it, you may be astound. in this article I’ll show you a way to read XML documents from EmbeddedResource in dot net 3.5

—————————————————————-

GNU Logo

GNU Logo

‪Title : ‪How to read Embedded Resource in c#

‪Publish Date : 14/12/2009

‪Version : 1.0

‪Author : Nasser Hajloo

‪Author Mail : n.hajloo@gmail.com

‪Copyright (c) 2009 Nasser Hajloo.

‪Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation;

‪with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”.

—————————————————————-

How To Embedd Resource

How To Embedd Resource

what is Embedded Resource?

Embedded Resources are whatever developer want to usein his/her assembly without informing end user that he/she is using them. this type of resources will embedd in assembly and will increasing assembly size. the important note about the embedded resource is that this type of files never resultto application change, because their embedd to assembly and end user can’t change them, so if you have and important resource that lack of that file will result to application error you should emmded that resource as an Emmbeded Resource.

Embedded Resource and Resource are so different and Resources will appear to end user and him/her can shange it, usually application translation packs are the commonly exampleof this type of resource, and end user with changing this file willface with translated application.

 

How to Embedd a Resource? embedding a resource in dot net is as easy of drinking a cup of coffee!. to embedd a resource, all you need is selct the object on Solution Explorer and then press F4 to open Properties window, in properties window you should , from the Advanced section you should select Embedded Reource in Build Action Property. all of this proccess showed in side picture.

using each type of embedded resource is different from others, and how to use an embedded image is different from how to use embedded xml resource. in this article I will describe how to use a xml embedded resource.

How To Read / Write into XML Embedded Resource? because of embeding xml into assembly, you should use a little Reflection to read/write data into embedded xml resource. all you should do is calling xml from inside of the assembly. for example


System.Reflection.Assembly asm = Assembly.GetExecutingAssembly();

System.IO.Stream xmlStream = asm.GetManifestResourceStream("Hajloo.FOSS.UnicodeConverter.EnterpriseAppUnit.ucd.all.flat.xml");

XmlReader reader = XmlReader.Create(xmlStream, settings);

in this example we create an object for our assembly (asm) and then use a Stream (you can use a xmlTextReader or vice versa) to read the xml, in this line of code we address the xml with complete path of XML. note that my XML name is ucd.all.flat.xml and dot between xml do not affect the clr to check another path, you should use complete Path + Name + Extension of the XML document.

in final line of code I create a XMLReader object (you can make a XMRWriter object to write inside of XML) to read (write) data from XML.

trick : if you can not find a correct path to your XML, in windows explorer right click on your assembly and then open it on Notepad++ or other editor. you can find all of you XML document inside of the assembly and you can see the fullpath of XML document here.

7 Responses to ‪How to read Embedded Resource in c#

  1. Oh my goodness! Incredible article dude! Thank you, However I am experiencing difficulties with your RSS.

    I don’t understand why I am unable to subscribe to it.
    Is there anyone else getting similar RSS issues? Anybody who knows the answer will you kindly respond?
    Thanks!!

  2. Aw, this was an extremely good post. Taking a few minutes and actual effort to create a good article… but what can I say… I procrastinate a lot and don’t manage to get anything done.

  3. My wife and i got quite joyous when Albert managed to round up his
    inquiry through your precious recommendations he had
    from your web pages. It is now and again perplexing to just be giving freely tricks that many other people could have been selling.
    Therefore we consider we need the writer to thank because of that.

    The illustrations you made, the straightforward
    website navigation, the relationships your site give support
    to create – it is most powerful, and it is making our son and our family understand
    the matter is fun, which is extremely pressing.
    Thanks for all!

  4. groepssex says:

    I simply wanted to develop a small remark to appreciate you for
    these remarkable points you are sharing at this website.
    My time intensive internet research has at the end been rewarded with extremely good facts and strategies to exchange with my friends.
    I ‘d state that that many of us site visitors are truly endowed to live in a wonderful website with very many lovely professionals with useful hints. I feel quite privileged to have encountered the web pages and look forward to plenty of more pleasurable minutes reading here. Thanks a lot again for all the details.

  5. Guys commonly do that reactively. It is too early to do that.
    Until you are just searching for a one particular evening hookup this gets men involved in you for the wrong good reasons.
    They use dating like a chance to determine how far they should go
    into the relationship, and mostly whether the relationship has a chance to
    withstand the high winds of emotions and the heightened human nature, all
    as an act of finding ways on which they will start living together.

    If he shows some, or even all of these signs – he’s truly in love
    with you! If he shows any of these five signs – he’s clearly in love with you.

    If you’ve pretended to be someone you’re not online, consider how tough it’ll
    be to keep that facade when you finally hook up.

    Nowadays, speed dating occasions have been customized in a way that caters for all the
    many kinds of people and their niche, for instance different sexualities, age groups and even professions.

    If you really want to know who a person is, do not give him/her time to rethink the words to
    define who he is. People at work see it in the way
    you have become the best performer, full of energy and
    obvious bravado. Do not open all your details and remember
    secrets always attract more than openness. Also, if you do
    not know these things, get out of the dating game
    and stay out of it until you know yourself and what you want in life.
    One photo showing an entire clothed body and another close-up photo should
    be enough to satisfy someone looking for a
    mate. Get out and savor the functions you are now attending,
    places where females and males are in plenty.

    The dating spree has brought into your life someone who cannot be replaced by anything or anyone in your existence, and your friends know it so
    well. It is a perfect recipe for failure. I believe that true happiness is found in true love.
    With mature dating, the web seems to have done justice to its very purpose..
    The chances where people meet through other channels are very few.
    Where someone lives is not the only thing to consider.
    Love makes us to be attracted and attached to only one person,
    while friendship can bring into the equation so many people.

    Penthouse, founded in 1965 by Bob Guccione, was acquired
    in 2004 by a group of investors headed by entrepreneur Marc Bell.

    Incase you do not enjoy your dating relationship rare yourself for a tough life with your partner, and a serious torture once you
    have had a family coming. The main benefit of registering on these websites
    is that you can tap a pool of countless individuals to find your very
    best self half.. This guy was definitely just like me.

    You want to stay away from dating? Are you looking for a
    fling or casual date?

    The research you do will help you find the best free dating sites, save on your finances, and increase your chances of finding someone special for you.
    Online dating is diverse. Many of these singles are so
    involved in matters pertaining to their careers to have the time to go
    places to socialize and meet interesting singles.

    This is the uniqueness of the on the web dating sites. I will no longer talk with him online as
    a spine is a requirement in the men I date. You may meet that person in a year or even more.
    Simply tell about desired quality and determined belongings about You and write your
    profile there.

    Simply begin your dating game bit by bit. When you
    think of it that way, divorce is a very sad thing. They long to
    feel that kind of closeness. Now that she has left, you no longer part the decisions in your life with anybody.
    Should you explore this avenue? Enjoy the dates you have, even if it isn’t the “one”.

    it’s too powerful!

    Be very careful on the way you express anger after your dating relationship has hit a snag, more
    so towards your partner and in the midst of other people.

    You can easily realize many years later how old you have
    become, while the beautiful ones have withered and others are yet to be born. They always plan them in advance to make sure
    they’re going to have a good time. While dating British men, keep in mind
    that they are not keen dancers. What are you waiting around
    for? They are more set in their ways and that can be bad thing
    if they have some bad habits.

    The art dating is like a drug, and once you get hooked to it you cannot tire from coming back for it.
    You’re prepared to begin a new life knowing these first
    date tips. It is pretty exciting to be matched to people from all walks of life
    in Scotland. Love contact sports Looking for someone to spend my
    fortune … The last thing that you want to
    appear like is as a prying stalker, while at the same time that you are looking for something extra
    about the person you will be dating. If and when you decide to meet in person, meet in a public place.
    There’s a way about how you need to word out your headline
    without coming off as needy, vague, or creepy.

    They’re definitely not washed up. Though it will be nice if you
    are genuine and creative, and come up with something of your own that suits you better.

    Suggestion of meeting in a third country which could be a trick to get a person on unfamiliar ground where they could be cheated more easily.

    Thus, use affirmative and positive headlines to make
    your profile an attractive one. You need to go on about
    20 dates just to get back in the swing of things with the current
    Dating World and practice your social poise and presentation. You are not traveling into an abyss of darkness but a clear path
    of light where the experience of others light your way.
    Unfortunately, I shared the information with the date…big mistake.

    Simple at heart and straightforward with opinions.
    Therefore, make a concise and interesting headline that will immediately grab their attention and will make them utterly inquisitive to dig into
    your profile. A good friend will give you his/her important views
    on your dating relationship.

  6. Hello mates, nice paragraph and fastidious urging commented here, I am truly enjoying
    by these.

  7. Pingback: how to write a classification essay

Leave a comment