Compartir a través de


del método WebPart.LoadResource

Devuelve una cadena que describe el nombre localizado, la categoría y la descripción del recurso especificado.

Espacio de nombres:  Microsoft.SharePoint.WebPartPages
Ensamblado:  Microsoft.SharePoint (en Microsoft.SharePoint.dll)

Sintaxis

'Declaración
Public Overridable Function LoadResource ( _
    id As String _
) As String
'Uso
Dim instance As WebPart
Dim id As String
Dim returnValue As String

returnValue = instance.LoadResource(id)
public virtual string LoadResource(
    string id
)

Parámetros

  • id
    Tipo: System.String

    Una cadena que especifica el identificador para el recurso.

Valor devuelto

Tipo: System.String
Una cadena que especifica los valores de propiedad localizados de Name, Categoryy Description del recurso definido por el ResourcesAttribute del recurso.

Ejemplos

En el ejemplo de código siguiente se muestra un elemento Web que reemplaza el método LoadResource . Para que este ejemplo funcione, debe agregar un recursos (.resx) a su proyecto de ensamblado. Para hacerlo en Microsoft Visual Studio 2005, haga clic en el ensamblado en el Explorador de soluciones, elija Agregar y, a continuación, haga clic en Agregar nuevo elemento. En el cuadro de diálogo Agregar nuevo elemento, seleccione Archivo de recursos de ensamblado y, a continuación, haga clic en Abrir.

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

Namespace WebControlLibrary4
   '/ <summary>
   '/ Summary description for WPLocalizedResource.
   '/ </summary>
   <XmlRoot([Namespace] := "MyNamespace"), ToolboxData("<{0}:WPLocalizedResource runat=server></{0}:WPLocalizedResource>")>  _
   Public Class WPLocalizedResource
      Inherits Microsoft.SharePoint.WebPartPages.WebPart

      Private Const c_MyText_Localized As String = "My Localized Property"
      Private _myText_Localized As String

      Public Sub New()
         _myText_Localized = c_MyText_Localized
      End Sub

      '---------------------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 Property MyText_Localized() As String
         Get
            Return _myText_Localized
         End Get
         Set
            _myText_Localized = value
         End Set
      End Property

      Public Overrides Function LoadResource(myID As String) As String
         Dim rm As New ResourceManager("WebControlLibrary4.Resource1", [Assembly].GetExecutingAssembly())
         Return rm.GetString(myID)
      End Function 'LoadResource

      '----------------------RENDER------------------------------------------
      Protected Overrides Sub RenderWebPart(output As HtmlTextWriter)
         output.Write(("<br>Localized Resource Property Value: " + Me.MyText_Localized))
      End Sub
   End Class
End Namespace
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);
        }
    }
}

Vea también

Referencia

clase WebPart

Miembros WebPart

Espacio de nombres Microsoft.SharePoint.WebPartPages