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
Синтакса:
SPUtility.GetLocalizedString(“$Resources:<<ResourceFileName,ResourceKeyName>>”, “<<ResourceFileName>>”, lang);
Пример:
SPUtility.GetLocalizedString(“$Resources:MyResources,Име”, “MyResources”, lang);
Sample Source:
користење на System;
користење на System.Runtime.InteropServices;
користење на System.Web.UI;
користење на System.Web.UI.WebControls;
користење на System.Web.UI.WebControls.WebParts;
користење на System.Xml.Serialization;
користење на Microsoft.SharePoint;
користење на Microsoft.SharePoint.WebControls;
користење на Microsoft.SharePoint.WebPartPages;
користење на Microsoft.SharePoint.Utilities;
namespace ResourceFile
{
[Раководство(“fc643df7-8836-41bf-913f-662ed57e659a”)]
јавноста
class
ResourceCollection : System.Web.UI.WebControls.WebParts.WebPart
{
низа Име;
низа Презиме;
јавноста ResourceCollection()
{
}
protected
override
поништат CreateChildControls()
{
base.CreateChildControls();
uint lang = SPContext.Current.Web.Language;
FirstName = SPUtility.GetLocalizedString(“$Resources:MyResources,Име”, “MyResources”, lang);
LastName = SPUtility.GetLocalizedString(“$Resources:MyResources,Презиме”, “MyResources”, lang);
}
protected
override
поништат Render(HtmlTextWriter writer)
{
writer.Write(“Value of First Name from Resource File : “ + Име);
writer.Write(“Value of Last Name from Resource File : “ + Презиме);
}
}
}
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/