First: Create a WSPBuilder Project(VS2008).File—New Project—WSPBuilder(Project Type)—WSPBuilder Project. Structure is under below:
Second: Copy these resource files to this path. (C:/Inetpub/wwwroot/wss/VirtualDirectories/41305/App_GlobalResources)
Note: please debug webpartfeature1.cs.Then check the value of System.Globalization.CultureInfo.CurrentCulture.If the value is zh-HK,we should change the resource file Demo.zh-CN.resx to Demo.zh-HK.resx.
Third:WSPBuilder—Build WSP—Deploy.The result is as following:
namespace Demo
{
[Guid("8164ff96-9e31-4ef7-9107-d08fed41382c")]
public class WebPartFeature1 : Microsoft.SharePoint.WebPartPages.WebPart
{
private bool _error = false;
private string _myProperty = null;
private string _lblUserName = null;
private string _txtUserName = null;
[Personalizable(PersonalizationScope.Shared)]
[WebBrowsable(true)]
[System.ComponentModel.Category("My Property Group")]
[WebDisplayName("MyProperty")]
[WebDescription("Meaningless Property")]
public string MyProperty
{
get
{
if (_myProperty == null)
{
_myProperty = "Hello SharePoint";
}
return _myProperty;
}
set { _myProperty = value; }
}
[WebBrowsable(true),
Personalizable(PersonalizationScope.Shared),
WebDescription("Login UserName Label"),
Category("Login Input"),
WebDisplayName("Login UserName Label")]
public string LblUserName
{
get
{
if (_lblUserName == null)
{
_lblUserName = HttpContext.GetGlobalResourceObject("Demo", "Text", System.Globalization.CultureInfo.CurrentCulture).ToString();
}
return _lblUserName;
}
set
{
_lblUserName = value;
}
}
[WebBrowsable(true),
Personalizable(PersonalizationScope.Shared),
WebDescription("Login UserName TextBox"),
Category("Login Input"),
WebDisplayName("Login UserName TextBox")]
public string TxtUserName
{
get
{
if (_txtUserName == null)
{
_txtUserName = HttpContext.GetGlobalResourceObject("Demo", "Title", System.Globalization.CultureInfo.CurrentCulture).ToString();
}
return _txtUserName;
}
set
{
_txtUserName = value;
}
}
public WebPartFeature1()
{
this.ExportMode = WebPartExportMode.All;
}
/// <summary>
/// Create all your controls here for rendering.
/// Try to avoid using the RenderWebPart() method.
/// </summary>
protected override void CreateChildControls()
{
if (!_error)
{
try
{
base.CreateChildControls();
// Your code here...
//this.Controls.Add(new LiteralControl(this.MyProperty));
UserControl uc = (UserControl)this.Page.LoadControl("/_controltemplates/Product/Product.ascx");
//no need to write to the following four line.when i deploy this code,no result.I add these lines.But the real reason is that,i don't install language package.Cofused for two days.:)
//Label lblName = (Label)uc.FindControl("Label1");
// lblName.Text = this.LblUserName;
// TextBox txtTitle = (TextBox)uc.FindControl("TextBox1");
//txtTitle.Text = this.TxtUserName;
this.Controls.Add(uc);
}
catch (Exception ex)
{
HandleException(ex);
}
}
}
}
3. Resource file code is following: