Clase ImageFieldValue
Una clase de valor de campo de un objeto ImageField que representa una etiqueta IMG y atributos específicos de clave para esa etiqueta.
Jerarquía de la herencia
System.Object
Microsoft.SharePoint.Publishing.Fields.HtmlTagValue
Microsoft.SharePoint.Publishing.Fields.ImageFieldValue
Espacio de nombres: Microsoft.SharePoint.Publishing.Fields
Ensamblado: Microsoft.SharePoint.Publishing (en Microsoft.SharePoint.Publishing.dll)
Sintaxis
'Declaración
<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
Comentarios
Este objeto de valor ajusta una cadena HTML para una imagen y permite obtener y establecer algunas propiedades del objeto de valor y, a continuación, obtener la etiqueta < IMG > resultante cadena de formato HTML. Si la propiedad ImageUrl no tiene un valor, el método ToString devuelve una cadena vacía. En otros casos, el método ToString devuelve una cadena con código HTML que contiene una etiqueta < IMG >, posiblemente entre un hipervínculo de etiqueta < A >, dependiendo de los valores de la propiedad Hyperlink . Sólo se reconocen determinadas propiedades en el < A > y < IMG > etiquetas y se utilizan para generar la cadena HTML.
Para la etiqueta < A >:
Href
Target (se permite sólo "_blank")
Para la etiqueta < IMG >:
Src (required)
Align
Alt
Border
Height
Hspace
Vspace
width
Para una columna ImageField , instancias normalmente se recuperan de un valor de campo SPListItem . SPListItem también se utiliza para almacenar el valor registrado en un control de RichImageField y RichImageSelector . Además, puede crear una nueva instancia directamente como un valor vacío o un valor basado en una cadena HTML que se ajusta al patrón básico de una etiqueta < IMG > opcionalmente entre en una etiqueta < A >. Después de recuperar este valor de un campo de SPListItem y cambiar las propiedades de este objeto, debe establecer el objeto de valor al valor del campo SPListItem y actualizarlo para almacenar el valor.
Ejemplos
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();
}
}
}
Seguridad para subprocesos
Los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para subprocesos. No se garantiza que los miembros de instancias sean seguros para los subprocesos.