Compartilhar via


ImageFieldValue classe

Uma classe de valor de campo de um objeto ImageField que representa uma tag IMG e atributos de chave específicos para essa marca.

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.Publishing.Fields.HtmlTagValue
    Microsoft.SharePoint.Publishing.Fields.ImageFieldValue

Namespace:  Microsoft.SharePoint.Publishing.Fields
Assembly:  Microsoft.SharePoint.Publishing (em Microsoft.SharePoint.Publishing.dll)

Sintaxe

'Declaração
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Class ImageFieldValue _
    Inherits HtmlTagValue
'Uso
Dim instance As ImageFieldValue
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class ImageFieldValue : HtmlTagValue

Comentários

Esse objeto de valor envolve uma cadeia de caracteres HTML para uma imagem e permite que você obter e definir determinadas propriedades de objeto de valor e, em seguida, obter a marca < IMG > resultante cadeia de caracteres de marcação HTML. Se a propriedade ImageUrl não tem um valor, o método ToString retorna uma seqüência vazia. Em outros casos, o método ToString retorna uma seqüência de caracteres de HTML que contém uma marca < IMG >, possivelmente entre um hiperlink de marca < A >, dependendo dos valores da propriedade Hyperlink . Somente determinadas propriedades são reconhecidas no < A > e < IMG > marcas e são usados para gerar a seqüência de caracteres HTML.

Para a marca < A >:

  • Href

  • Target (apenas blank"é permitido)

Para a marca < IMG >:

  • Src (required)

  • Align

  • Alt

  • Border

  • Height

  • Hspace

  • Vspace

  • width

Para uma coluna de ImageField , instâncias são geralmente recuperadas de um valor do campo SPListItem . SPListItem também é usado para armazenar o valor lançado em um controle RichImageField e RichImageSelector . Além disso, você pode construir uma nova instância diretamente como um valor vazio ou um valor com base em uma seqüência de caracteres HTML que está de acordo com o padrão básico de uma marca < IMG > opcionalmente colocado em uma marca < A >. Depois que você recuperar o valor de um campo SPListItem e altere as propriedades neste objeto, você deve definir o objeto de valor para o valor do campo SPListItem e atualizá-lo para armazenar o valor.

Exemplos

using SPListItem = Microsoft.SharePoint.SPListItem;
using ImageFieldValue = Microsoft.SharePoint.Publishing.Fields.ImageFieldValue;

namespace Microsoft.SDK.SharePointServer.Samples
{
    public static class ImageFieldValueSamples
    {
    // You can change any of the following data that are set into the ImageFieldValue
    private const string NewImageUrl = "/SiteCollectionImages/SampleImage.jpg";
    private const string NewHyperlink = "/Pages/SamplePage.aspx";
    private const bool NewOpenHyperlinkInNewWindow = true;
    private const string NewAlignment = "right";
    private const string NewAlternateText = "Sample alternate text for the image";
    private const int NewBorderWidth = 4;
    private const int NewHeight = 100;
    private const int NewWidth = 150;
    private const int NewHorizontalSpacing = 10;
    private const int NewVerticalSpacing = 15;

    // You can change the following default ImageFieldValue HTML
    private const string DefaultImageFieldValueHtml = "<A href=\"/Pages/SamplePage.aspx\"><IMG src=\"/SiteCollectionImages/SampleImage.jpg\" alt=\"Default ALT attribute value\"></a>";

    public static string GetAndSetImageFieldValue(
    SPListItem listItemWithImageField,
    string imageFieldName)
    {
      if (null == listItemWithImageField)
      {
        throw new System.ArgumentNullException("listItemWithImageField", "The listItemWithImageField argument must be a valid SPListItem");
      }

      if (string.IsNullOrEmpty(imageFieldName))
      {
         throw new System.ArgumentNullException("imageFieldName", "The imageFieldName argument must be a valid image field name on the SPListItem");
      }

      // Retrieve the current value from an SPListItem with a
      // column of the ImageField type with the name imageFieldName
      ImageFieldValue currentFieldValue = 
      listItemWithImageField[imageFieldName] as ImageFieldValue;

      // If there is no current value then construct a new empty value
      if (null == currentFieldValue)
      {
         currentFieldValue = new ImageFieldValue();
      }

      // If this property is not set to a value then the ToString() for
      // the ImageFieldValue returns String.Empty and nothing is stored
      // in the field value when it is set back into the SPListItem.
      currentFieldValue.ImageUrl = NewImageUrl;

      // These properties are all optional for an ImageFieldValue
      currentFieldValue.Hyperlink = NewHyperlink;
      currentFieldValue.OpenHyperlinkInNewWindow = NewOpenHyperlinkInNewWindow;
      currentFieldValue.Alignment = NewAlignment;
      currentFieldValue.AlternateText = NewAlternateText;
      currentFieldValue.BorderWidth = NewBorderWidth;
      currentFieldValue.Height = NewHeight;
      currentFieldValue.Width = NewWidth;
      currentFieldValue.HorizontalSpacing = NewHorizontalSpacing;
      currentFieldValue.VerticalSpacing = NewVerticalSpacing;

      // The changes to the properties of the ImageFieldValue object are
      // local to this specific object instance and not stored in the SPListItem.
      // To store the changes the value must be set back in to the SPListItem field value.
     listItemWithImageField[imageFieldName] = currentFieldValue;
     listItemWithImageField.Update();

     // The ToString() returns the HTML that reflects the new ImageFieldValue properties
     return currentFieldValue.ToString();
    }
  }
}

Segurança de thread

Os membros públicos estática (Shared no Visual Basic) desse tipo são seguros para thread. Nenhum membro de instância pode ser garantido como seguro para thread.

Ver também

Referência

ImageFieldValue membros

Microsoft.SharePoint.Publishing.Fields namespace

ImageUrl

ToString

ImageField

ValidateImageValue

Item

Value

Value