When you first start looking through a SharePoint 2007 aspx page you realise that there isn’t an awful lot of actual changeable code in them. Its is pretty much impossible to decode the cryptic references used by the ASP.NET controls, such as text boxes, labels and SharePoint:SPLinkButton.
An example of what I mean can be seen below;
<SharePoint:SPLinkButton id="idNavLinkViewAll" runat="server"
NavigateUrl="~site/_layouts/viewlsts.aspx" Text="<%$Resources:wss,quiklnch_allcontent%>" AccessKey="<%$Resources:wss,quiklnch_allcontent_AK%>" />
The item in bold, $Resources:wss,quiklnch_allcontent, will be translated to View All Site Content when the page is displayed in the browser. I’ve used this example from the GLOBAL default.master page as in this case, it is a little more obvious as to what it means. It makes it a little easier to understand when you see one that does make sense!
So, what is happening here?
Rather than hard code all of these textual elements, some of which are repeated on many pages, their values are stored in a Resource file. This allows the developer to change the value in just the one place, where it will be picked up by all of the pages that reference it.
Before we look at the format of the resource file, it’s time for a quick tip:
Tip Start
You’ve found the wss.resx file under the 12 hive’s CONFIG\Resources directory. You have made some changes and checked your web page. It hasn’t picked the changes up even though you have performed an IISRESET. Why is this not working? Well, the CONFIG\Resources directory holds the master copy of the resx files. The one you need to amend will be sitting under;
drive:\inetput\wwwroot\wss\VirtualDirectories\app_name\App_GlobalResources
The directory path may be different depending on your installation. Don’t get confused; once you make the changes in this directory, it will work.
Tip Finish
The App_GlobalResources directory contains a host of resx files. Many of them will be named so that it is (reasonably) apparent which bit of SharePoint uses them.
Tip Start
It’s also worth noting that each web application has its own set of resx files. This means that you can tailor the messages for each web application.
Tip Finish
If we navigate to the App_GlobalResources directory and take a copy of wss.resx we can open it up for editing to see how the file is constructed.
Don’t worry about the top portion of the file for now, we are more interested in the name / value pairs further down.
<data name="quiklnch_allcontent">
<value>View All Site Content</value>
</data>
The name / value pair shown in the code above is the text called by $Resources:wss,quiklnch_allcontent from the code we looked at earlier. Breaking this down further we see that $Resources: tells SharePoint that it needs to look in its resources library for the translation. WSS is the name of the resource file and quiklnch_allcontent is the name within the resource file that contains the translation text, View All Site Content.
If you were to change the contents between the <value>…</value> tags, the changes would be picked up by all aspx pages that referenced it. You can, of course, update the wss.resx file yourself. Ideally, I believe that you would want to create your own custom resource file by copying wss.resx and removing the name / value pairs that you don’t need and putting in your own.
To do this, create a copy of wss.resx and call it myapplication.resx. Edit the file and remove everything below the first name / value pair. In the case of wss.resx this will be
<data name="accessDenied_pagetitle">
<value>Error: Access Denied</value>
</data>
Change the name=”…” and <value>…</value> tags as required. You can repeat the three lines to add more name / value pairs.
Once you have made all of your changes, save the file and make sure it is in the App_GlobalResources directory of your chosen application.
To reference your new resource file, place the following code within your aspx page(s);
<%$Resources: myapplication, data_name_label%>
For example, if you had created a name / value pair called
<data name="site_welcome_message">
<value>Hello, welcome to my site!</value>
</data>
You would reference it as;
<%$Resources: myapplication, site_welcome_message%>
Where-ever you used the reference above, the text “Hello, welcome to my site!” would be displayed.
Resource files are an efficient way to manage static text in this way. It is also possible to embed HTML within the <value>…</value> tags. Here is an example;
<data name="folders_pagetitleintitlearea">
<value><![CDATA[View Folders in <a href="{0}">{1}</a>]]></value>
</data>
Hopefully this post will help you understand all of these references to $Resource that you see in SharePoint 2007 aspx pages and will act as a starting point for you to create your own resource files.
I am still on a learning curve with SharePoint 2007 so please point out any errors or omissions, and please let me know if you found this helpful.
As always, your comments on my posts are welcome.
Until next time…
Comments