Multi-Language Demo (MOSS)

First: Create a WSPBuilder Project(VS2008).File—New Project—WSPBuilder(Project Type)—WSPBuilder Project. Structure is under below:

structure

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:

result

 

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:

resoure files

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值