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

Синтакса:

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 : “ + Презиме);

}

}

}

1 comment to How to Use Resource File in SharePoint 2007

Оставете Одговор

Можете да ги користите овие HTML таговите

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