Home


.Net, SQL and softball. Musings of a software developer with a softball problem

Tuesday, December 23, 2008

.Net Resource Files

Resource files in .Net will allow you to create customized values for either different languages or if you are using an the same app for multiple people on different servers, you can store things like titles, names, and other specific version info that you don't want to hard code.

You can store the resource file (resx) in either the App_GlobalResources or the App_LocalResources folder depending on the scope of the resource.

The values in the resource file are stored as XML as key/value pairs. Pretty easy stuff, and you can store pictures, text, icons, or audio...anything really in here.

To get things out of the resource file you can either bind it to a label (or any other bindable control)
<asp:label id="label1" text="'<%$resources:ClassName,Property">' runat="Server" />
Where ClassName is the name of the resource file without the .resx extension on it, and Property is the key.

Or if you wan to access the key value pair programmatically you can access a global resource by using this
HttpContext.GetGlobalResourceObject("ClassName", "Property")
or you can access a local resource by using
HttpContext.GetLocalResourceObject("virpath", "Property")
where you pass in the virtual path of the local resource object.

I used these two articles as reference

Labels:

posted by Tom Becker at

0 Comments:

Post a Comment

<< Home