Export (0) Print
Expand All

WebPart.LoadResource method

Returns a string that describes the localized name, category, and description of the specified resource.

Namespace:  Microsoft.SharePoint.WebPartPages
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public virtual string LoadResource(
	string id
)

Parameters

id
Type: System.String

A string that specifies the identifier for the resource.

Return value

Type: System.String
A string that specifies the localized Name, Category, and Description property values of the resource as defined by the ResourcesAttribute of the resource.

The following code example shows a Web Part that overrides the LoadResource method. For this example to work, you must add a resource (.resx) to your assembly project. To do that in Microsoft Visual Studio 2005, right-click your assembly in Solution Explorer, point to Add, and then click Add New Item. In the Add New Item dialog box, select Assembly Resource File, and then click Open.

using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint;
using System.Xml.Serialization;
using System.Collections.Specialized;
using System.Collections;
using System.Resources;
using System.Reflection;
using System.Drawing;
using System.Globalization;

namespace WebControlLibrary4
{
    /// <summary>
    /// Summary description for WPLocalizedResource.
    /// </summary>

    [XmlRoot(Namespace="MyNamespace")]
    [ToolboxData("<{0}:WPLocalizedResource runat=server></{0}:WPLocalizedResource>")]
    public class WPLocalizedResource : Microsoft.SharePoint.WebPartPages.WebPart
    {

        const string c_MyText_Localized = "My Localized Property";
        private string _myText_Localized;

        public WPLocalizedResource() 
        {
            _myText_Localized = c_MyText_Localized;
        }

        //---------------------RESOURCES-----LOCALIZATION------------------------------
        //Property that is localized. Use the ResourceAttibute.
        //[ResourcesAttribute (PropertyNameID=1, CategoryID=2, DescriptionID=3)]
        [ResourcesAttribute ("1","2","3")]
        [Category("Cool Properties")]
        [DefaultValue(c_MyText_Localized), WebPartStorage(Storage.Personal)]
        [FriendlyNameAttribute("My Text Localized"), Description("MyText Localized")]
        public string MyText_Localized
        {
            get
            {
                return _myText_Localized;
            }
            set
            {
                _myText_Localized = value;
            }
        }
        public override string LoadResource (string myID)
        {
            ResourceManager rm = new ResourceManager("WebControlLibrary4.Resource1",Assembly.GetExecutingAssembly());
            return rm.GetString(myID);
        }

        //----------------------RENDER------------------------------------------
        protected override void RenderWebPart(HtmlTextWriter output)
        {
            output.Write("<br>Localized Resource Property Value: " + this.MyText_Localized);
        }
    }
}

Community Additions

Show:
© 2014 Microsoft