Create Resource file using Visual Studio IDE
Copy the resource file into 12 hive resource folder
GetLocalized method from SPUtility to read the values from resource file
Syntax:
SPUtility.GetLocalizedString(“$Resources:<<ResourceFileName,ResourceKeyName>>”, “<<ResourceFileName>>”, lang);
Example:
SPUtility.GetLocalizedString(“$Resources:MyResources,FirstName”, “MyResources”, lang);
Sample Source:
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Utilities;
namespace ResourceFile
{
[Guid(“fc643df7-8836-41bf-913f-662ed57e659a”)]
public
class
ResourceCollection : System.Web.UI.WebControls.WebParts.WebPart
{
string FirstName;
string LastName;
public ResourceCollection()
{
}
protected
override
void CreateChildControls()
{
base.CreateChildControls();
uint lang = SPContext.Current.Web.Language;
FirstName = SPUtility.GetLocalizedString(“$Resources:MyResources,FirstName”, “MyResources”, lang);
LastName = SPUtility.GetLocalizedString(“$Resources:MyResources,LastName”, “MyResources”, lang);
}
protected
override
void Render(HtmlTextWriter writer)
{
writer.Write(“Value of First Name from Resource File : “ + FirstName);
writer.Write(“Value of Last Name from Resource File : “ + LastName);
}
}
}
Veri nice article. In my blog I have similar article on how to use SPUtility.GetLocalizedString – http://dotnetfollower.com/wordpress/2011/05/the-usage-of-sputility-getlocalizedstring/