guyS's WebLog

IShare, My DotNet Fingerprint

Using Embedded Resource in your application

When u want to attach your application assembly file additional information that located in a file (XML, Txt, image or other type) you can attach it as Embedded Resource.

The advantages I can raise for doing so r :

1.) You do not need to deploy the embedded resource attach file with your application. Its part of the assembly.

2.) You don't need to set read permissions on file system folders and files because you attach the file you need as part of your assembly

3.) You don't expose your embedded resource content as u its been done when the file you attach is not part of the assembly. This is especially what u would like to achieve when your embedded resource is an XML that define specific configuration information

How to attach a DataSet (xml/xsd files pair) to an assembly as a embedded resource:

Create two files XML, XSD that represent the DataSet

u should right click on each of the files-->choose properties

In properties window u should set the Build Action value to embedded resource

In order to retrieve the resources and construct the DataSet from the XML/XSD we should do the following:

We first define in the Global class a static member that will be use to hold the loaded DataSet

internal static DataSet dsErrors=null; //we will keep there different Error Messages

[Static members at the Global  class in web applications r excellent for sharing at application level - with performance advantage over Application collection object]

Then we need to load the DataSet

protected void Application_Start(Object sender, EventArgs e)

{

Global.dsErrors = new DataSet("Errors");

string xmlResouce = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".ApplicationErrors.xsd";

using (Stream s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(xmlResouce))

{

Global.dsErrors.ReadXmlSchema(s);

}

xmlResouce = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".ApplicationErrors.xml";

using (Stream s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(xmlResouce))

{

Global.dsErrors.ReadXml(s);

}

}

by using xml file to hold global application information we can enjoy the VS.NET XML editor which enables us an easy way to edit our file, sorting the data within it and browsing it when we have hierarchy data

 

Comments

Seriously... said:

Scrap the blog if you don't know how to write correctly.  This isn't text messaging, so "u" and "r" should not be substitutes for "you" and "are".

It's two more letters you stupid trendy asshole.

# March 18, 2008 11:12 PM

Dude... said:

You just wasted 100 or so keystrokes writing a worthless comment, you douche bag.

# April 15, 2008 6:39 PM

Agree said:

Sorry...I have to agree with "Seriously.." above. That shit drives me nuts. It's just lame. Really.

I mean, I was impressed with the knowledge presented and thought it was a worthy post, but with the "u" and the "r" it felt like I was getting a text message from my little high school age sister.

If u want ppl 2 read this blog 4eva, u r gonna have 2 stop typing like this. I promise.

# April 17, 2008 11:32 AM

moid said:

is there any way to update xml in resource file?

# July 2, 2008 6:53 AM

idiots said:

who cares about how its written, as long as you got some useful information.

some people are real cry babes who deserve to be shot

# September 25, 2008 11:20 PM

yarly said:

I have to agree with idiots.  Let's try to whine and cry like sissies.  Did you understand the blog? I understood it.  u fagboi loozurz.

# October 7, 2008 3:53 PM

yeah... said:

Good info, but unpleasant to read.  Spend just a second or two to proof read your post.  

"You don't expose your embedded resource content as u its been done when the file you attach is not part of the assembly."

And to you guys who think its okay to type in text lingo, it is fine in the context of casual conversation.  But, the point of this post was to transfer technical know-how.  Let's try not to evolve the english language into a lazy grouping of letters that, when in their final form don't even resemble an English word.  "fagboi".. ?

# February 13, 2009 12:23 PM

me said:

Good post man, i dont mind if you are using "u" and "r" as long as I can read it or we

# March 17, 2009 6:13 AM

AliG said:

Hey,

In the whole post, I only understood the 'r' and 'u' words...

Can you please go over the tech stuff and explain in common lingo :]

# April 21, 2009 1:42 PM

ParkyRander said:

I didn't get as far as finding out whether the blog had any usefull information or not, the u and r's usage just made it too painfull to read.

AliG comment made me laugh though so all was not lost.

# May 15, 2009 5:25 PM

SeeSharper said:

Text shortcuts aside the article is still useful, however you assumed that the resource was at the root level of the assembly, if you have placed the resource within a directory under the main assembly the namespace will not be at the root level, remember to append your namespace change to the beginning of the resource name, i.e. string.concat(Assembly.GetExecutingAssembly().GetName().Name,".folder.resourceName"). One side note, u should use string.concat(s1,s2) instead of string + string. The rest of you should stop your QQ and STFU.

# June 25, 2009 4:01 PM

Chris said:

Maybe he posted the the blog from his phone. If so, you gotta hand it to him typing out all that code through the phone.

# July 8, 2009 2:48 PM

rulame? said:

have to agree u r dumb 4 writing like this

save the abbreviations for your cell phone

# November 4, 2009 2:05 PM

craiggeil said:

I agree, put down your blackberry and write your words in full. It's aggravating to read.

# May 11, 2010 1:41 PM

GreenHorse said:

While the writing style is up to the writer (opinion), writing this way causes alot of tangential comments that take away from what you are saying.  Perhaps you should consider this when posting in the future.  By the time I read the whole thing I forgot what the subject was.

# May 25, 2010 11:01 PM

mayavi said:

be careful,while writing blogs,anyway i understood the matter...

# May 26, 2010 6:27 AM

ReadingToLearn said:

Nice post. I did think it odd to see r and u in a post, but as long as you continue to share your knowledge you are still ahead of me.

# August 24, 2010 3:51 PM

mk said:

whatever the style of writing was, the code was really helpful to me.

Thanks

# June 18, 2011 12:52 PM

glm said:

U gave sum gr8 info pal!

U R D Man!

Sorry. I actually gave up on reading your blog entry when I realized that you couldn't write in plain English. I didn't feel like I could trust code advice written by a twelve-year-old.

# July 19, 2011 12:54 PM

buy oem software said:

OT60h9 wow, awesome article post.

# May 2, 2012 12:47 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)