zoukankan      html  css  js  c++  java
  • MultiLanguage WebPart简单引用

    WebPart多语言的实现:

    WPResource.cs

    View Code
    using System;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    using System.ComponentModel;
    using System.Web;

    namespace WebPartCollection.Common
    {

    public static class WPResource
    {
    const string RESOURCE_FILE_NAME = "Anson";
    /// <summary>
    /// 获取资源字符串的值
    /// </summary>
    /// <param name="key">资源字符串key</param>
    /// <returns></returns>
    public static string GetString(string key)
    {
    try
    {
    string value = "" + HttpContext.GetGlobalResourceObject(RESOURCE_FILE_NAME, key);
    //value = ""+HttpContext.GetGlobalResourceObject(RESOURCE_FILE_NAME, key, System.Threading.Thread.CurrentThread.CurrentCulture);
    if (value == "")
    return key;
    else
    return value;
    }
    catch (Exception ex)
    {
    throw new SPException("access resource file [" + RESOURCE_FILE_NAME + "] error,please confirm files in App_GlobalResources.", ex);
    }
    }
    }

    /// <summary>
    /// 属性分类,名称从资源中获取
    /// </summary>
    public class ResCategoryAttribute : CategoryAttribute
    {
    public ResCategoryAttribute(string key)
    : base(key)
    { }

    protected override string GetLocalizedString(string value)
    {
    return WPResource.GetString(value);
    }
    }

    /// <summary>
    /// 属性显示名,从资源中获取
    /// </summary>
    public class ResWebDisplayNameAttribute : WebDisplayNameAttribute
    {
    public ResWebDisplayNameAttribute(string key)
    : base(key)
    { }

    public override string DisplayName
    {
    get
    {
    return WPResource.GetString(base.DisplayName);
    }
    }
    }


    public class ResConnectionProviderAttribute : ConnectionProviderAttribute
    {
    public ResConnectionProviderAttribute(string name) : base(name)
    {
    }

    public ResConnectionProviderAttribute(string name,string id) : base(name,id)
    {
    }

    public override string DisplayName
    {
    get
    {
    return WPResource.GetString(base.DisplayName);
    }
    }
    }

    public class ResConnectionConsumerAttribute : ConnectionConsumerAttribute
    {
    public ResConnectionConsumerAttribute(string name)
    : base(name)
    {
    }

    public ResConnectionConsumerAttribute(string name, string id)
    : base(name, id)
    {
    }

    public override string DisplayName
    {
    get
    {
    return WPResource.GetString(base.DisplayName);
    }
    }
    }
    }

    WebPart文件代码:

    View Code
    using System;
    using System.Runtime.InteropServices;
    using System.Web.UI.WebControls.WebParts;

    using WebPartCollection.Common;

    namespace WebPartCollection
    {
    [Guid("c91e5b6c-702f-4716-b4df-2d70858e57cc")]
    public class MutilanguageWebPart : System.Web.UI.WebControls.WebParts.WebPart
    {
    public MutilanguageWebPart()
    {
    }

    private string _URL;
    [WebBrowsable,Personalizable]
    [ResCategory("XMLURL")]
    [ResWebDisplayName("XMLURL")]
    public string URL
    {
    get { return _URL; }
    set { _URL = value; }
    }
    protected override void CreateChildControls()
    {
    base.CreateChildControls();
    }
    }
    }

    最后一步,新建两个资源文件,分别是Anson.resx和Anson.zh-CN.resxy,在两个两个文件添加key为XMLURL,及value,最后保存,把这两个文件放端口下的App_GlobalResources文件夹,如90\App_GlobalResources

  • 相关阅读:
    ENVI数据格式
    旋转卡壳模板
    旋转卡壳求两个凸包最近距离poj3608
    树状数组模板
    输入输出挂
    Catalan数以及使用Raney引理证明
    【转】AC神组合数取模大全
    单向HASH——MurmurHash
    hdu4063(圆与圆交+线段与圆交+最短路)
    字符串HASH模板
  • 原文地址:https://www.cnblogs.com/gzh4455/p/2198922.html
Copyright © 2011-2022 走看看