Accessing other resource files in your web application

Using GetLocalResourceObject() to access resource files from other resource objects.
 
I have been doing some work on localising (localizing…no pun intended) a website. One of the issues I have found is that there may be an occassion that I would want to access the resource key from other local resource objects. For example, I can use GetLocalResourceObject("resourceKey1.Text") to get a text value for the current ASPX page that I am working on. I can also use the HttpContext class to access the same resource keys by specifiying HttpContext.GetLocalResourceObject(Page.AppRelativeVirtualPath, "resourceKey1.Text");
 
So, this got me thinking. Can I do the same think to access resource keys for another page using the same method? The answer is, Yes. I just need to replace the Page.AppRelativeVirtualPath with a virtual path to the page I am interested in and look for the relevant resource key in the resource file. For example, HttpContext.GetLocalResourceObject("~/MyFolder/MyPage.aspx", "resourceKey2.Text" ); will find the entry for resourceKey2.Text in the resource file MyPage.aspx.resx in the App_LocalResources folder.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s