Freigeben über


AssetUrlSelector-Klasse

Rendert ein HTML-Eingabefeld und eine Schaltfläche oder generiert ein ECMAScript, das das Dialogfeld Ressourcenauswahl zur Auswahl einer Link- oder Bild-URL aus einer Websitesammlung öffnet.

Vererbungshierarchie

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 (in Microsoft.SharePoint.Publishing.dll)

Syntax

'Declaration
<ValidationPropertyAttribute("AssetUrl")> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class AssetUrlSelector _
    Inherits WebControl _
    Implements INamingContainer, IPostBackEventHandler, ICompositeInputControl
'Usage
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

Hinweise

Sie können ein Objekt dieser Klasse als einfaches Serversteuerelement verwenden, das ein Textfeld und eine Browserschaltfläche als HTML-Benutzeroberfläche (UI) bereitstellt. Mit dem Objekt können Sie eine URL auswählen, die auf ein Objekt in der aktuellen Websitesammlung verweist. Die AssetUrl-Eigenschaft des Serversteuerelements zeigt den aktuellen Wert der im Textfeld ausgewählten URL an.

Sie können das Verhalten und die Darstellung des Dialogfelds anpassen und die Anzeige des Textfelds und der Schaltfläche durch Festlegen der Eigenschaften des Steuerelements ändern. Standardmäßig wird das Dialogfeld Ressourcenauswahl geöffnet, in dem der Benutzer eine Link-URL auswählen kann. Es verweist entweder auf den aktuellen Speicherort AssetUrl oder auf den zuletzt gespeicherten Speicherort, von dem der Benutzer eine Link-URL in einem Dialogfeld Ressourcenauswahl ausgewählt hat. Wenn kein aktueller oder gespeicherter Speicherort vorhanden ist, verweist Ressourcenauswahl standardmäßig auf eine angegebene DefaultOpenLocationUrl-Eigenschaft oder auf die bekannten Speicherorte für die aktuelle Website und Websitesammlung, die im Abschnitt Suchen in auf der linken Seite des Dialogfelds Ressourcenauswahl dargestellt wird. Wenn der Benutzer eine URL im Dialogfeld Ressourcenauswahl auswählt oder eingibt und es dann schließt, wird die URL standardmäßig dem Textfeld AssetUrlSelector hinzugefügt.

Sie können die AssetUrl-Eigenschaft zum Abrufen dieses Werts aus dem Dialogfeld Ressourcenauswahl nach einem Postbackereignis verwenden. Diese Klasse kann auch zum Öffnen des Dialogfelds Ressourcenauswahl aus einem anderen HTML-Element als der bereitgestellten Schaltfläche verwendet werden. In diesem Fall können Sie die Eigenschaften Visible(), AssetPickerButtonVisible oder AssetUrlTextBoxVisible auf false festlegen und mit der GetClientLaunchPickerReference-Methode eine ECMAScript (JavaScript, JScript)-Zeichenfolge zurückgeben, mit der Sie das Dialogfeld Ressourcenauswahl mit einer onClick-Clientfunktion als HTML-Element oder einer ECMAScript (JavaScript, JScript)-Funktion öffnen können. Sie müssen die GetClientLaunchPickerReference-Methode vor oder während der OnPreRender-Phase des Lebenszyklus der Seite aufrufen und Eigenschaften vor dem Aufruf der Methode festlegen, damit der richtige Client- ECMAScript (JavaScript, JScript)-Code auf der Seite registriert wird.

Alle Änderungen an den Eigenschaften des Steuerelements nach dem Aufrufen der GetClientLaunchPickerReference-Methode wirken sich nicht auf das Verhalten des Dialogfelds aus, da das Clientskript zur Steuerung des Dialogfelds bereits auf der Seite registriert ist. Sie können ein Objekt dieser Klasse instanziieren, indem Sie es der ASPX-Seite hinzufügen oder indem Sie es mithilfe des AssetUrlSelector-Konstruktors den untergeordneten Steuerelementen für ein Control- oder Page-Objekt hinzufügen.

Beispiele

Die Codebeispiele für diese Klasse können in jedem Microsoft Visual C#-Websteuerelement oder CodeBehind-Projekt hinzugefügt werden. Sie benötigen Verweise auf System.Web und Microsoft.SharePoint.Publishing.

In diesem Beispiel werden AddVisibleAssetUrlSelectorControl und GenerateAssetUrlSelectorLaunchScript veranschaulicht. Jedes Beispiel veranschaulicht in dieser Klasse verfügbare Eigenschaften und Methoden.

  • Das AddVisibleAssetUrlSelectorControl-Beispiel erstellt ein AssetUrlSelector-Steuerelement, definiert seine Eigenschaften und Verhaltensweisen bei Ereignissen und fügt das Steuerelement dem Dialogfeld Ressourcenauswahl hinzu.

  • Das GenerateAssetUrlSelectorLaunchScript-Beispiel erstellt ein Skript, das ein AssetUrlSelector-Objekt generiert und einer Steuerelementauflistung auf einer Website Textfelder hinzufügt.

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

Threadsicherheit

Alle öffentlichen static (Shared in Visual Basic) Member dieses Typs sind threadsicher. Die Threadsicherheit von Instanzmembern ist nicht gewährleistet.

Siehe auch

Referenz

AssetUrlSelector-Member

Microsoft.SharePoint.Publishing.WebControls-Namespace

AssetUrl

AssetUrlTextBoxVisible

AssetUrlClientID

AssetPickerButtonVisible

DefaultOpenLocationUrl