How to Use Resource File in SharePoint 2007

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);

}

}

}

1 comment to How to Use Resource File in SharePoint 2007

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>