Compartilhar via


AssetUrlSelector classe

Processa um campo de entrada de HTML e botão ou gera ECMAScript que abre a caixa de diálogo Seletor de ativo usada para selecionar uma URL da imagem ou link de um conjunto de sites.

Inheritance hierarchy

System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.WebControl
      Microsoft.SharePoint.Publishing.WebControls.AssetUrlSelector

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

Sintaxe

'Declaração
<ValidationPropertyAttribute("AssetUrl")> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class AssetUrlSelector _
    Inherits WebControl _
    Implements INamingContainer, IPostBackEventHandler, ICompositeInputControl
'Uso
Dim instance As AssetUrlSelector
[ValidationPropertyAttribute("AssetUrl")]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class AssetUrlSelector : WebControl, 
    INamingContainer, IPostBackEventHandler, ICompositeInputControl

Comentários

Você pode usar um objeto dessa classe como um controle de servidor simples que fornece uma caixa de texto e uma interface de usuário HTML do botão navegador (UI). Você pode usar o objeto para selecionar uma URL que aponta para um objeto no conjunto de sites atual. A propriedade AssetUrl do controle do servidor mostra o valor atual da URL selecionado na caixa de texto.

Você pode personalizar o comportamento e a aparência da caixa de diálogo e alterar a exibição da caixa de texto e botão, definindo as propriedades do controle. Por padrão, a caixa de diálogo Seletor de ativo é aberta para permitir que o usuário selecione um URL do link e aponta para o local atual de AssetUrl ou o local armazenado a última da qual o usuário selecionou um URL do link em um Selecionador de ativo. Se não houver nenhum local atual ou está armazenado, em seguida, os padrões de Selecionador de ativo para qualquer propriedade de DefaultOpenLocationUrl foi especificada, ou para os locais conhecidos para o site atual e um conjunto de sites que é apresentado na seção Examinar no lado esquerdo da caixa de diálogo Seletor de ativo . Por padrão, quando o usuário seleciona ou digita uma URL na caixa de diálogo Seletor de ativo e fechá-lo, a URL é adicionada à caixa de texto AssetUrlSelector .

Você pode usar a propriedade AssetUrl para obter esse valor na caixa de diálogo Seletor de ativo após um evento de postagem. Essa classe também pode ser usada para abrir a caixa de diálogo Seletor de ativos de um elemento HTML que não seja o botão fornecido. Nesse caso, você pode definir a propriedade Visible(), AssetPickerButtonVisibleou AssetUrlTextBoxVisible para false e use o método GetClientLaunchPickerReference para retornar uma seqüência de caracteres de ECMAScript (JavaScript, JScript) que você pode usar para abrir a caixa de diálogo Seletor de ativos com uma função de onClick de cliente de elemento HTML ou ECMAScript (JavaScript, JScript) . Você deve chamar o método GetClientLaunchPickerReference antes ou durante a fase de OnPreRender de ciclo de vida da página, e você deve definir as propriedades antes de chamar esse método para o cliente correto ECMAScript (JavaScript, JScript) registrar na página.

As alterações nas propriedades do controle após chamar o método GetClientLaunchPickerReference não afetam o comportamento da caixa de diálogo porque o script de cliente que está controlando a caixa de diálogo já está registrado na página. Você pode instanciar um objeto dessa classe, adicione-o à página ASPX ou usando o construtor de AssetUrlSelector e adicioná-lo aos controles filho para um objeto Control ou Page .

Exemplos

Os exemplos de código para essa classe podem ser adicionados a qualquer projeto de controle ou code-behind Web Microsoft Visual C#. Eles exigem referências a System.Web e Microsoft.SharePoint.Publishing.

Este exemplo demonstra como AddVisibleAssetUrlSelectorControl e GenerateAssetUrlSelectorLaunchScript. Cada exemplo demonstra métodos e propriedades disponíveis nesta classe.

  • O exemplo AddVisibleAssetUrlSelectorControl cria um controle AssetUrlSelector , define suas propriedades e comportamentos em eventos e adiciona o controle à caixa de diálogo Seletor de ativo .

  • O exemplo GenerateAssetUrlSelectorLaunchScript cria um script que gera um objeto AssetUrlSelector e adiciona caixas de texto para uma coleção de controles em um site.

using Control = System.Web.UI.Control;
using TextBox = System.Web.UI.WebControls.TextBox;
using ButtonType = System.Web.UI.WebControls.ButtonType;
using AssetUrlSelector = Microsoft.SharePoint.Publishing.WebControls.AssetUrlSelector;

namespace Microsoft.SDK.SharePointServer.Samples
{public static class AssetUrlSelectorSamples{
// You can change any of the following default const data
//  used in the AssetUrlSelector samples.

// These values control the appearance of the text box
// and button for the control
private const bool SampleAssetPickerButtonVisible = true;
private const bool SampleAssetUrlTextBoxVisible = true;
private const ButtonType SampleButtonType = ButtonType.Image;
private const string SampleCssTextBox = "sample-textbox-css";
private const string SamplePickerButtonImage = "/_layouts/images/icdoc.gif";
private const string SamplePickerButtonText = "Sample Button Text";

private const bool SampleAutoPostBack = true;
private const bool SampleDecodeUrlPath = true;
private const int SampleMaxLength = 100;
private const bool SampleValidateUrl = true;
private const bool SampleIsUrlRequired = true;
private const bool SampleAllowExternalUrls = false;

// These values control the appearance and behavior
// of the Asset Picker dialog box.
private const string SampleDefaultOpenLocationUrl = "~Site/Pages/";
private const bool SampleDefaultToLastUsedLocation = false;
private const bool SampleDisplayLookInSection = false;
private const bool SampleUseImageAssetPicker = false;
private const string SampleOverrideDialogDescription = "This is a sample description";
private const string SampleOverrideDialogFeatures = "resizable: yes; status: yes; scroll: yes; help: no; 
dialogWidth:730px; dialogHeight:500px;";
private const string SampleOverrideDialogImageUrl = "/_layouts/images/icdoc.gif";
private const string SampleOverrideDialogTitle = "Sample Selection Dialog Title";

// These values control the complex client script behaviors.
// This must be ECMAScript returning a function object.
private const string ScriptClientCallback = "function(newAssetUrl, newAssetText, 
configObject, returnedValue) { window.alert('Client callback with returned url value: ' + newAssetUrl); }";
   // This must be ECMAScript returning a string   // value for asset URL data.
private const string ScriptGetAssetUrlValue = "window.location.href";

// AddVisibleAssetUrlSelectorControl - 
// This sample constructs an AssetUrlSelector with 
// various settings and adds it to a control collection
// in a Web page.  The sample function takes in one
// required argument:
//
// containerControl: The control for which the created
// AssetUrlSelector is added as a child control
public static void AddVisibleAssetUrlSelectorControl(Control containerControl)
{if (null == containerControl){
throw new System.ArgumentNullException("containerControl", 
"The containerControl argument must not be null");}
if (null == containerControl.Page){
throw new System.ArgumentException
("The containerControl argument must be a control in a System.Web.UI.Page control tree");}
// Create the AssetUrlSelectorAssetUrlSelector assetSelector = new AssetUrlSelector();
// Set values for the appearance of the text box and // button for the control.assetSelector.AssetPickerButtonVisible = SampleAssetPickerButtonVisible;assetSelector.AssetUrlTextBoxVisible = SampleAssetUrlTextBoxVisible;assetSelector.ButtonType = SampleButtonType;assetSelector.CssTextBox = SampleCssTextBox;assetSelector.PickerButtonImage = SamplePickerButtonImage;assetSelector.PickerButtonText = SamplePickerButtonText;
// Set values for the behavior and validation// for the text box.assetSelector.AutoPostBack = SampleAutoPostBack;assetSelector.DecodeUrlPath = SampleDecodeUrlPath;assetSelector.MaxLength = SampleMaxLength;assetSelector.ValidateUrl = SampleValidateUrl;assetSelector.IsUrlRequired = SampleIsUrlRequired;assetSelector.AllowExternalUrls = SampleAllowExternalUrls;
// Set values for the appearance and behavior of the Asset Picker dialog box.assetSelector.DefaultOpenLocationUrl = SampleDefaultOpenLocationUrl;assetSelector.DefaultToLastUsedLocation = SampleDefaultToLastUsedLocation;assetSelector.DisplayLookInSection = SampleDisplayLookInSection;assetSelector.OverrideDialogDescription = SampleOverrideDialogDescription;assetSelector.OverrideDialogFeatures = SampleOverrideDialogFeatures;assetSelector.OverrideDialogImageUrl = SampleOverrideDialogImageUrl;assetSelector.OverrideDialogTitle = SampleOverrideDialogTitle;assetSelector.UseImageAssetPicker = SampleUseImageAssetPicker;
// Sets an event handler for when the AssetUrl value changes on a postback.assetSelector.AssetUrlChanged += 
delegate(object sender, System.EventArgs ev)
{ string newAssetUrlValue = ((AssetUrlSelector)sender).AssetUrl;
// Perform event handling operations based on the newAssetUrlValue. 
};
// Add the configured assetSelector to the controls on the page.containerControl.Controls.Add(assetSelector);
}

// GenerateAssetUrlSelectorLaunchScript
// This sample constructs an AssetUrlSelector with
// various settings and adds visible text boxes to a control
// collection on a Web 
// page, setting their double-click ECMAScript 
// events to open an Asset Picker dialog box. The sample function
// takes in one required argument and one optional argument:
//
// containerControl: The control for which the created
//TextBox controls are added as a child control
//
// launchPickerWithCurrentBrowserUrl: Determines
// whether the current AssetUrl property value or the
// current browser URL 
// value should be used when launching the Asset Picker.
public static string GenerateAssetUrlSelectorLaunchScript(Control containerControl,bool launchPickerWithCurrentBrowserUrl)
{if (null == containerControl){
throw new System.ArgumentNullException("containerControl", 
"The containerControl argument must not be null");}
if (null == containerControl.Page){
throw new System.ArgumentException("The containerControl argument must be a 
valid control in a System.Web.UI.Page control tree");}
TextBox assetUrlControl = new TextBox();TextBox assetTextControl = new TextBox();
// Add these text boxes to the container control so that// they get a completed ClientID property for // their container control.//  containerControl.Controls.Add(assetUrlControl);containerControl.Controls.Add(assetTextControl);
AssetUrlSelector assetSelector = new AssetUrlSelector();
// Setting the Page and ID properties is required when the// AssetUrlSelector control is not added to the page// control tree because// the AssetUrlSelector.GetClientLaunchPickerReference()// method needs to register script in the pageassetSelector.Page = containerControl.Page;assetSelector.ID = "SampleGenerateAssetUrlSelectorLaunchScript";
// Uses text box client ID to connect the Asset// Picker to the text boxes for the resulting//  URL and default text values returned from the// Asset Picker dialog box.assetSelector.AssetUrlClientID = assetUrlControl.ClientID;assetSelector.AssetTextClientID = assetTextControl.ClientID;
// Set the ECMAScript to perform after populating the text boxes // with the returned valuesassetSelector.ClientCallback = ScriptClientCallback;

string clientLaunchPickerScript;if(launchPickerWithCurrentBrowserUrl){
// Use a client launch script that calculates
// the current asset URL with custom ECMAScript
// which in this example always is the current browser location URL
clientLaunchPickerScript = assetSelector.GetClientLaunchPickerReference(ScriptGetAssetUrlValue);}else{
// Use the default client launch script that gets the
// current asset URL value based on the AssetUrlClientID
clientLaunchPickerScript = assetSelector.GetClientLaunchPickerReference();}
// Add the client launch script as an ondoubleclick handler for the two text boxesassetUrlControl.Attributes["ondblclick"] = clientLaunchPickerScript + "; return false;";assetTextControl.Attributes["ondblclick"] = clientLaunchPickerScript + "; return false;";
// Return the client launch script, which can be added to other ECMAScript on the pagereturn clientLaunchPickerScript;
}}
}
Imports Control = System.Web.UI.Control
Imports TextBox = System.Web.UI.WebControls.TextBox
Imports ButtonType = System.Web.UI.WebControls.ButtonType
Imports AssetUrlSelector = Microsoft.SharePoint.Publishing.WebControls.AssetUrlSelector

Namespace Microsoft.SDK.SharePointServer.SamplesPublic NotInheritable Class AssetUrlSelectorSamples
' You can change any of the following default const data
'  used in the AssetUrlSelector samples.

' These values control the appearance of the text box
' and button for the control
Private Const SampleAssetPickerButtonVisible As Boolean = True
Private Const SampleAssetUrlTextBoxVisible As Boolean = True
Private Const SampleButtonType As ButtonType = ButtonType.Image
Private Const SampleCssTextBox As String = "sample-textbox-css"
Private Const SamplePickerButtonImage As String = "/_layouts/images/icdoc.gif"
Private Const SamplePickerButtonText As String = "Sample Button Text"

Private Const SampleAutoPostBack As Boolean = True
Private Const SampleDecodeUrlPath As Boolean = True
Private Const SampleMaxLength As Integer = 100
Private Const SampleValidateUrl As Boolean = True
Private Const SampleIsUrlRequired As Boolean = True
Private Const SampleAllowExternalUrls As Boolean = False

' These values control the appearance and behavior
' of the Asset Picker dialog box.
Private Const SampleDefaultOpenLocationUrl As String = "~Site/Pages/"
Private Const SampleDefaultToLastUsedLocation As Boolean = False
Private Const SampleDisplayLookInSection As Boolean = False
Private Const SampleUseImageAssetPicker As Boolean = False
Private Const SampleOverrideDialogDescription As String = "This is a sample description"
Private Const SampleOverrideDialogFeatures As String = "resizable: yes; status: yes; scroll: yes; help: no; dialogWidth:730px; dialogHeight:500px;"
Private Const SampleOverrideDialogImageUrl As String = "/_layouts/images/icdoc.gif"
Private Const SampleOverrideDialogTitle As String = "Sample Selection Dialog Title"

' These values control the complex client script behaviors.
' This must be ECMAScript returning a function object.
Private Const ScriptClientCallback As String = "function(newAssetUrl, newAssetText, configObject, returnedValue) { window.alert('Client callback with returned url value: ' + newAssetUrl); }"
   ' This must be ECMAScript returning a string   ' value for asset URL data.
Private Const ScriptGetAssetUrlValue As String = "window.location.href"

' AddVisibleAssetUrlSelectorControl - 
' This sample constructs an AssetUrlSelector with 
' various settings and adds it to a control collection
' in a Web page.  The sample function takes in one
' required argument:
'
' containerControl: The control for which the created
' AssetUrlSelector is added as a child control
Private Sub New()
End Sub
Public Shared Sub AddVisibleAssetUrlSelectorControl(ByVal containerControl As Control)If Nothing Is containerControl Then
Throw New System.ArgumentNullException("containerControl", "The containerControl argument must not be null")End If
If Nothing Is containerControl.Page Then
Throw New System.ArgumentException ("The containerControl argument must be a control in a System.Web.UI.Page control tree")End If
' Create the AssetUrlSelectorDim assetSelector As New AssetUrlSelector()
' Set values for the appearance of the text box and ' button for the control.assetSelector.AssetPickerButtonVisible = SampleAssetPickerButtonVisibleassetSelector.AssetUrlTextBoxVisible = SampleAssetUrlTextBoxVisibleassetSelector.ButtonType = SampleButtonTypeassetSelector.CssTextBox = SampleCssTextBoxassetSelector.PickerButtonImage = SamplePickerButtonImageassetSelector.PickerButtonText = SamplePickerButtonText
' Set values for the behavior and validation' for the text box.assetSelector.AutoPostBack = SampleAutoPostBackassetSelector.DecodeUrlPath = SampleDecodeUrlPathassetSelector.MaxLength = SampleMaxLengthassetSelector.ValidateUrl = SampleValidateUrlassetSelector.IsUrlRequired = SampleIsUrlRequiredassetSelector.AllowExternalUrls = SampleAllowExternalUrls
' Set values for the appearance and behavior of the Asset Picker dialog box.assetSelector.DefaultOpenLocationUrl = SampleDefaultOpenLocationUrlassetSelector.DefaultToLastUsedLocation = SampleDefaultToLastUsedLocationassetSelector.DisplayLookInSection = SampleDisplayLookInSectionassetSelector.OverrideDialogDescription = SampleOverrideDialogDescriptionassetSelector.OverrideDialogFeatures = SampleOverrideDialogFeaturesassetSelector.OverrideDialogImageUrl = SampleOverrideDialogImageUrlassetSelector.OverrideDialogTitle = SampleOverrideDialogTitleassetSelector.UseImageAssetPicker = SampleUseImageAssetPicker
' Sets an event handler for when the AssetUrl value changes on a postback.AddHandler assetSelector.AssetUrlChanged, Sub(sender As Object, ev As System.EventArgs) Dim newAssetUrlValue As String = (CType(sender, AssetUrlSelector)).AssetUrl
' Add the configured assetSelector to the controls on the page.containerControl.Controls.Add(assetSelector)
End Sub

' GenerateAssetUrlSelectorLaunchScript
' This sample constructs an AssetUrlSelector with
' various settings and adds visible text boxes to a control
' collection on a Web 
' page, setting their double-click ECMAScript 
' events to open an Asset Picker dialog box. The sample function
' takes in one required argument and one optional argument:
'
' containerControl: The control for which the created
'TextBox controls are added as a child control
'
' launchPickerWithCurrentBrowserUrl: Determines
' whether the current AssetUrl property value or the
' current browser URL 
' value should be used when launching the Asset Picker.
Public Shared Function GenerateAssetUrlSelectorLaunchScript(ByVal containerControl As Control, ByVal launchPickerWithCurrentBrowserUrl As Boolean) As StringIf Nothing Is containerControl Then
Throw New System.ArgumentNullException("containerControl", "The containerControl argument must not be null")End If
If Nothing Is containerControl.Page Then
Throw New System.ArgumentException("The containerControl argument must be a valid control in a System.Web.UI.Page control tree")End If
Dim assetUrlControl As New TextBox()Dim assetTextControl As New TextBox()
' Add these text boxes to the container control so that' they get a completed ClientID property for ' their container control.'  containerControl.Controls.Add(assetUrlControl)containerControl.Controls.Add(assetTextControl)
Dim assetSelector As New AssetUrlSelector()
' Setting the Page and ID properties is required when the' AssetUrlSelector control is not added to the page' control tree because' the AssetUrlSelector.GetClientLaunchPickerReference()' method needs to register script in the pageassetSelector.Page = containerControl.PageassetSelector.ID = "SampleGenerateAssetUrlSelectorLaunchScript"
' Uses text box client ID to connect the Asset' Picker to the text boxes for the resulting'  URL and default text values returned from the' Asset Picker dialog box.assetSelector.AssetUrlClientID = assetUrlControl.ClientIDassetSelector.AssetTextClientID = assetTextControl.ClientID
' Set the ECMAScript to perform after populating the text boxes ' with the returned valuesassetSelector.ClientCallback = ScriptClientCallback

Dim clientLaunchPickerScript As StringIf launchPickerWithCurrentBrowserUrl Then
' Use a client launch script that calculates
' the current asset URL with custom ECMAScript
' which in this example always is the current browser location URL
clientLaunchPickerScript = assetSelector.GetClientLaunchPickerReference(ScriptGetAssetUrlValue)Else
' Use the default client launch script that gets the
' current asset URL value based on the AssetUrlClientID
clientLaunchPickerScript = assetSelector.GetClientLaunchPickerReference()End If
' Add the client launch script as an ondoubleclick handler for the two text boxesassetUrlControl.Attributes("ondblclick") = clientLaunchPickerScript & "; return false;"assetTextControl.Attributes("ondblclick") = clientLaunchPickerScript & "; return false;"
' Return the client launch script, which can be added to other ECMAScript on the pageReturn clientLaunchPickerScript
End FunctionEnd Class
End Namespace

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

AssetUrlSelector membros

Microsoft.SharePoint.Publishing.WebControls namespace

AssetUrl

AssetUrlTextBoxVisible

AssetUrlClientID

AssetPickerButtonVisible

DefaultOpenLocationUrl