Freigeben über


SummaryLink-Klasse

Ein SummaryLink-Objekt, das eine Möglichkeit zum Speichern von Webadressen bereitstellt.

Vererbungshierarchie

System.Object
  Microsoft.SharePoint.Publishing.SummaryLink

Namespace:  Microsoft.SharePoint.Publishing
Assembly:  Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)

Syntax

'Declaration
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SummaryLink
'Usage
Dim instance As SummaryLink
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SummaryLink

Hinweise

Ein SummaryLink ist ein Hyperlink mit Anmerkungen.

Mindestens enthält ein SummaryLink -Objekt eine titleund ein linkUrl. Er enthält außerdem die Stilinformationen, die beeinflussen, wie es durch den SummaryLinkFieldControl oder SummaryLinkWebPartwiedergegeben wird.

Beispiele

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Publishing.Fields;
using Microsoft.SharePoint.Publishing.WebControls;
using SharePointWebParts = Microsoft.SharePoint.WebPartPages;
using System.Web.UI.WebControls.WebParts;

namespace SummaryLinkFieldTest
{
    static class CreateSummaryLinks
    {
        /// Creates SummaryLinks in a SummaryLinkField within a PublishingPage
        /// This sample creates group headers and summary links within a SummaryLinkFieldValue object
        /// and then applies the SummaryLinkFieldValue to a SummaryLinkField within a Page.
        /// 
        /// Pre-requisite:
        /// This sample assumes that 'Content Approval' is applied to 
        /// the Pages document library containing the PublishingPage.
        /// <param name="publishingPage">The page in which to create the summary links</param>
        /// <param name="fieldName">The name of the SummaryLinkField</param>
        public static void createFieldControlSummaryLinks(PublishingPage publishingPage, string fieldName)
        {
            // SummaryLinkFieldValue is the container for SummaryLinks and display configuration
            // data.
            SummaryLinkFieldValue summaryLinkValue = CreateSummaryLinks.createSummaryLinkValue();

            if (publishingPage.ListItem.File.CheckOutStatus == SPFile.SPCheckOutStatus.None)
            {
                publishingPage.CheckOut();
            }
            
            // Replace the existing contents of the field with the newly created SummaryLinkValue
            publishingPage.ListItem[fieldName] = summaryLinkValue;

            publishingPage.Update();
            publishingPage.CheckIn("Checking in summary link change");
            publishingPage.ListItem.File.Publish("Publishing summary link change");
            publishingPage.ListItem.File.Approve("Approving summary link change");
        }

        
        /// Creates SummaryLinks in a SummaryLinkWebPart within a PublishingPage
        /// This sample creates group headers and summary links within a SummaryLinkFieldValue object
        /// and then applies the SummaryLinkFieldValue to a SummaryLinkWebPart on a PublishingPage.
        /// 
        /// Pre-requisite:
        /// This sample assumes that 'Content Approval' is applied to 
        /// the Pages document library containing the PublishingPage.
        /// <param name="publishingPage">The page in which to create the summary links</param>
        /// <param name="webRelativePageUrl">The web relative URL of the page</param>
        /// <param name="webPartTitle">The Title of the web part</param>
        public static void createWebPartSummaryLinks(PublishingPage publishingPage, string webRelativePageUrl, string webPartTitle)
        {
            SummaryLinkFieldValue summaryLinkValue = CreateSummaryLinks.createSummaryLinkValue();

            if (publishingPage.ListItem.File.CheckOutStatus == SPFile.SPCheckOutStatus.None)
            {
                publishingPage.CheckOut();
            }

            SharePointWebParts.SPLimitedWebPartManager webPartManager =
                publishingPage.ListItem.Web.GetLimitedWebPartManager(webRelativePageUrl,
                                                          System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

            SharePointWebParts.SPLimitedWebPartCollection webParts = webPartManager.WebParts;

            foreach (WebPart webPart in webParts)
            {
                SummaryLinkWebPart slwp = webPart as SummaryLinkWebPart;
                if (slwp != null && 
                    string.CompareOrdinal(slwp.Title, webPartTitle) == 0)
                {
                    // Replace the existing contents of the Web part with the newly created SummaryLinkValue
                    slwp.SummaryLinkValue = summaryLinkValue;
                    webPartManager.SaveChanges(slwp);
                    break;
                }
            }

            publishingPage.Update();
            publishingPage.CheckIn("Checking in summary link change");
            publishingPage.ListItem.File.Publish("Publishing summary link change");
            publishingPage.ListItem.File.Approve("Approving summary link change");
        }

        public static SummaryLinkFieldValue createSummaryLinkValue()
        {
            SummaryLinkFieldValue summaryLinkValue = new SummaryLinkFieldValue();
            summaryLinkValue.DisplayColumns = 2;
            summaryLinkValue.LinkStyle = "Bullets";
            summaryLinkValue.GroupStyle = "Black";

            SummaryLinkCollection summaryLinks = summaryLinkValue.SummaryLinks;

            SummaryLink summaryLink;

            // Add Groups and links.
            // The link style set here must correspond to one of the template names in the XSL Item style
            // This is not verified by the OM, but an incorrect template name results in the
            // link not rendering.
            
            // GroupA

            summaryLink = summaryLinks.Add("GroupA");
            summaryLink.IsGroupHeader = true;

            summaryLink = summaryLinks.Add("Link1");
            summaryLink.Description = "Description1";
            summaryLink.Style = "Default";
            summaryLink.ImageUrl = "http://www.live.com/live/1.100.7.337/img/wl_jewel.gif";
            summaryLink.LinkUrl = "http://www.example.com/link1";

            summaryLink = summaryLinks.Add("Link2");
            summaryLink.Description = "Description2";
            summaryLink.Style = "Default";
            summaryLink.ImageUrl = "http://www.live.com/live/1.100.7.337/img/wl_jewel.gif";
            summaryLink.LinkUrl = "http://www.example.com/link2";

            // GroupB

            summaryLink = summaryLinks.Add("GroupB");
            summaryLink.IsGroupHeader = true;

            summaryLink = summaryLinks.Add("Link3");
            summaryLink.Description = "Description3";
            summaryLink.Style = "Default";
            summaryLink.ImageUrl = "http://www.live.com/live/1.100.7.337/img/wl_jewel.gif";
            summaryLink.LinkUrl = "http://www.example.com/link3";
            summaryLink.LinkToolTip = "Tooltip for link3";

            return summaryLinkValue;
        }
    
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Publishing
Imports Microsoft.SharePoint.Publishing.Fields
Imports Microsoft.SharePoint.Publishing.WebControls
Imports SharePointWebParts = Microsoft.SharePoint.WebPartPages
Imports System.Web.UI.WebControls.WebParts

Namespace SummaryLinkFieldTest
    Friend NotInheritable Class CreateSummaryLinks
        ''' Creates SummaryLinks in a SummaryLinkField within a PublishingPage
        ''' This sample creates group headers and summary links within a SummaryLinkFieldValue object
        ''' and then applies the SummaryLinkFieldValue to a SummaryLinkField within a Page.
        ''' 
        ''' Pre-requisite:
        ''' This sample assumes that 'Content Approval' is applied to 
        ''' the Pages document library containing the PublishingPage.
        ''' <param name="publishingPage">The page in which to create the summary links</param>
        ''' <param name="fieldName">The name of the SummaryLinkField</param>
        Private Sub New()
        End Sub
        Public Shared Sub createFieldControlSummaryLinks(ByVal publishingPage As PublishingPage, ByVal fieldName As String)
            ' SummaryLinkFieldValue is the container for SummaryLinks and display configuration
            ' data.
            Dim summaryLinkValue As SummaryLinkFieldValue = CreateSummaryLinks.createSummaryLinkValue()

            If publishingPage.ListItem.File.CheckOutStatus = SPFile.SPCheckOutStatus.None Then
                publishingPage.CheckOut()
            End If

            ' Replace the existing contents of the field with the newly created SummaryLinkValue
            publishingPage.ListItem(fieldName) = summaryLinkValue

            publishingPage.Update()
            publishingPage.CheckIn("Checking in summary link change")
            publishingPage.ListItem.File.Publish("Publishing summary link change")
            publishingPage.ListItem.File.Approve("Approving summary link change")
        End Sub


        ''' Creates SummaryLinks in a SummaryLinkWebPart within a PublishingPage
        ''' This sample creates group headers and summary links within a SummaryLinkFieldValue object
        ''' and then applies the SummaryLinkFieldValue to a SummaryLinkWebPart on a PublishingPage.
        ''' 
        ''' Pre-requisite:
        ''' This sample assumes that 'Content Approval' is applied to 
        ''' the Pages document library containing the PublishingPage.
        ''' <param name="publishingPage">The page in which to create the summary links</param>
        ''' <param name="webRelativePageUrl">The web relative URL of the page</param>
        ''' <param name="webPartTitle">The Title of the web part</param>
        Public Shared Sub createWebPartSummaryLinks(ByVal publishingPage As PublishingPage, ByVal webRelativePageUrl As String, ByVal webPartTitle As String)
            Dim summaryLinkValue As SummaryLinkFieldValue = CreateSummaryLinks.createSummaryLinkValue()

            If publishingPage.ListItem.File.CheckOutStatus = SPFile.SPCheckOutStatus.None Then
                publishingPage.CheckOut()
            End If

            Dim webPartManager As SharePointWebParts.SPLimitedWebPartManager = publishingPage.ListItem.Web.GetLimitedWebPartManager(webRelativePageUrl, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared)

            Dim webParts As SharePointWebParts.SPLimitedWebPartCollection = webPartManager.WebParts

            For Each webPart As WebPart In webParts
                Dim slwp As SummaryLinkWebPart = TryCast(webPart, SummaryLinkWebPart)
                If slwp IsNot Nothing AndAlso String.CompareOrdinal(slwp.Title, webPartTitle) = 0 Then
                    ' Replace the existing contents of the Web part with the newly created SummaryLinkValue
                    slwp.SummaryLinkValue = summaryLinkValue
                    webPartManager.SaveChanges(slwp)
                    Exit For
                End If
            Next webPart

            publishingPage.Update()
            publishingPage.CheckIn("Checking in summary link change")
            publishingPage.ListItem.File.Publish("Publishing summary link change")
            publishingPage.ListItem.File.Approve("Approving summary link change")
        End Sub

        Public Shared Function createSummaryLinkValue() As SummaryLinkFieldValue
            Dim summaryLinkValue As New SummaryLinkFieldValue()
            summaryLinkValue.DisplayColumns = 2
            summaryLinkValue.LinkStyle = "Bullets"
            summaryLinkValue.GroupStyle = "Black"

            Dim summaryLinks As SummaryLinkCollection = summaryLinkValue.SummaryLinks

            Dim summaryLink As SummaryLink

            ' Add Groups and links.
            ' The link style set here must correspond to one of the template names in the XSL Item style
            ' This is not verified by the OM, but an incorrect template name results in the
            ' link not rendering.

            ' GroupA

            summaryLink = summaryLinks.Add("GroupA")
            summaryLink.IsGroupHeader = True

            summaryLink = summaryLinks.Add("Link1")
            summaryLink.Description = "Description1"
            summaryLink.Style = "Default"
            summaryLink.ImageUrl = "http://www.live.com/live/1.100.7.337/img/wl_jewel.gif"
            summaryLink.LinkUrl = "http://www.example.com/link1"

            summaryLink = summaryLinks.Add("Link2")
            summaryLink.Description = "Description2"
            summaryLink.Style = "Default"
            summaryLink.ImageUrl = "http://www.live.com/live/1.100.7.337/img/wl_jewel.gif"
            summaryLink.LinkUrl = "http://www.example.com/link2"

            ' GroupB

            summaryLink = summaryLinks.Add("GroupB")
            summaryLink.IsGroupHeader = True

            summaryLink = summaryLinks.Add("Link3")
            summaryLink.Description = "Description3"
            summaryLink.Style = "Default"
            summaryLink.ImageUrl = "http://www.live.com/live/1.100.7.337/img/wl_jewel.gif"
            summaryLink.LinkUrl = "http://www.example.com/link3"
            summaryLink.LinkToolTip = "Tooltip for link3"

            Return summaryLinkValue
        End Function

    End 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

SummaryLink-Member

Microsoft.SharePoint.Publishing-Namespace

SummaryLinkFieldControl

SummaryLinkWebPart

SummaryLinkCollection

BeginColumn