방법: 서버 탐색기에서 SharePoint 노드 확장

서버 탐색기SharePoint 연결 노드 아래에 있는 노드를 확장할 수 있습니다. 이렇게 하면 새 자식 노드, 바로 가기 메뉴 항목 또는 속성을 기존 노드에 추가하려는 경우에 유용합니다. 자세한 내용은 서버 탐색기에서 SharePoint 연결 노드 확장을 참조하십시오.

서버 탐색기에서 SharePoint 노드를 확장하려면

  1. 클래스 라이브러리 프로젝트를 만듭니다.

  2. 다음 어셈블리에 대한 참조를 추가합니다.

    • Microsoft.VisualStudio.SharePoint

    • Microsoft.VisualStudio.SharePoint.Explorer.Extensions

    • System.ComponentModel.Composition

  3. IExplorerNodeTypeExtension 인터페이스를 구현하는 클래스를 만듭니다.

  4. 클래스에 System.ComponentModel.Composition.ExportAttribute 특성을 추가합니다. 이 특성을 사용하면 Visual Studio에서 IExplorerNodeTypeExtension 구현을 찾아 로드할 수 있습니다. IExplorerNodeTypeExtension 형식을 특성 생성자에 전달합니다.

  5. 클래스에 ExplorerNodeTypeAttribute 특성을 추가합니다. 이 특성은 확장할 노드의 형식을 나타내는 문자열 식별자를 지정합니다.

    Visual Studio에서 제공되는 기본 제공 노드 형식을 지정하려면 다음 열거형 값 중 하나를 특성 생성자에 전달합니다.

    • ExplorerNodeTypes: 사이트 연결 노드(사이트 URL을 표시하는 노드), 사이트 노드 또는 다른 모든 부모 노드를 지정하려면 서버 탐색기에서 이러한 값을 사용합니다.

    • ExtensionNodeTypes. SharePoint 사이트의 개별 구성 요소를 나타내는 기본 제공 노드, 즉 목록, 필드 또는 콘텐츠 형식을 나타내는 노드 중 하나를 지정하려면 이러한 값을 사용합니다.

  6. IExplorerNodeTypeExtension.Initialize 메서드 구현에서 nodeType 매개 변수의 멤버를 사용하여 노드에 기능을 추가합니다. 이 매개 변수는 IExplorerNodeEvents 인터페이스에 정의된 이벤트에 대한 액세스를 제공하는 IExplorerNodeType 개체입니다. 예를 들어, 다음과 같은 이벤트를 처리할 수 있습니다.

예제

다음 코드 예제에서는 두 가지 다른 유형의 노드 확장을 만드는 방법을 보여 줍니다.

  • 상황에 맞는 메뉴 항목을 SharePoint 사이트 노드에 추가하는 확장. 메뉴 항목을 클릭하면 클릭한 노드의 이름이 표시됩니다.

  • Body라는 필드를 나타내는 각 노드에 ContosoExampleProperty라는 사용자 지정 속성을 추가하는 확장

Imports System.ComponentModel
Imports System.ComponentModel.Composition
Imports System.Windows.Forms
Imports Microsoft.VisualStudio.SharePoint
Imports Microsoft.VisualStudio.SharePoint.Explorer
Imports Microsoft.VisualStudio.SharePoint.Explorer.Extensions

Namespace Contoso.ServerExplorerExtension
    <Export(GetType(IExplorerNodeTypeExtension))> _
    <ExplorerNodeType(ExplorerNodeTypes.SiteNode)> _
    Friend Class SiteNodeExtensionWithContextMenu
        Implements IExplorerNodeTypeExtension

        Private Sub Initialize(ByVal nodeType As IExplorerNodeType) _
            Implements IExplorerNodeTypeExtension.Initialize
            AddHandler nodeType.NodeMenuItemsRequested, AddressOf NodeMenuItemsRequested
        End Sub

        Private Sub NodeMenuItemsRequested(ByVal Sender As Object, ByVal e As ExplorerNodeMenuItemsRequestedEventArgs)
            Dim menuItem = e.MenuItems.Add("Display Message")
            AddHandler menuItem.Click, AddressOf MenuItemClick
        End Sub

        Private Sub MenuItemClick(ByVal Sender As Object, ByVal e As MenuItemEventArgs)
            Dim node As IExplorerNode = CType(e.Owner, IExplorerNode)
            MessageBox.Show(String.Format("Clicked the menu item for the '{0}' node.", node.Text))
        End Sub
    End Class

    <Export(GetType(IExplorerNodeTypeExtension))> _
    <ExplorerNodeType(ExtensionNodeTypes.FieldNode)> _
    Friend Class FieldNodeExtensionWithProperty
        Implements IExplorerNodeTypeExtension

        Private Sub Initialize(ByVal nodeType As IExplorerNodeType) _
            Implements IExplorerNodeTypeExtension.Initialize
            AddHandler nodeType.NodePropertiesRequested, AddressOf NodePropertiesRequested
        End Sub

        Private Sub NodePropertiesRequested(ByVal Sender As Object, ByVal e As ExplorerNodePropertiesRequestedEventArgs)
            Dim propertyObject As ExampleProperty = Nothing

            ' Only add the property to "Body" fields.
            If e.Node.Text = "Body" Then
                ' If the properties object already exists for this node, get it from the node's annotations.
                If False = e.Node.Annotations.TryGetValue(propertyObject) Then
                    ' Otherwise, create a new properties object and add it to the annotations.
                    propertyObject = New ExampleProperty(e.Node)
                    e.Node.Annotations.Add(propertyObject)
                End If
                e.PropertySources.Add(propertyObject)
            End If
        End Sub
    End Class

    Friend Class ExampleProperty

        Private node As IExplorerNode
        Private Const propertyId As String = "Contoso.CustomActionTestProperty"
        Private Const propertyDefaultValue As String = "This is a test value."

        Friend Sub New(ByVal node As IExplorerNode)
            Me.node = node
        End Sub

        ' Gets or sets a simple string property. 
        <DisplayName("ContosoExampleProperty")> _
        <DescriptionAttribute("This is an example property for field nodes.")> _
        <DefaultValue(propertyDefaultValue)> _
        Public Property TestProperty As String
            Get
                Dim propertyValue As String = Nothing

                ' Get the current property value if it already exists; otherwise, return a default value.
                If False = node.Annotations.TryGetValue(propertyId, propertyValue) Then
                    propertyValue = propertyDefaultValue
                End If
                Return propertyValue
            End Get
            Set(ByVal value As String)
                If value <> propertyDefaultValue Then
                    ' Store the property value in the Annotations property of the node. 
                    ' Data in the Annotations property does not persist when Visual Studio exits.
                    node.Annotations(propertyId) = value
                Else
                    ' Do not save the default value.
                    node.Annotations.Values.Remove(propertyId)
                End If
            End Set
        End Property
    End Class
End Namespace
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Windows.Forms;
using Microsoft.VisualStudio.SharePoint;
using Microsoft.VisualStudio.SharePoint.Explorer;
using Microsoft.VisualStudio.SharePoint.Explorer.Extensions;

namespace Contoso.ServerExplorerExtension
{
    [Export(typeof(IExplorerNodeTypeExtension))]
    [ExplorerNodeType(ExplorerNodeTypes.SiteNode)]
    internal class SiteNodeExtensionWithContextMenu : IExplorerNodeTypeExtension
    {
        public void Initialize(IExplorerNodeType nodeType)
        {
            nodeType.NodeMenuItemsRequested += nodeType_NodeMenuItemsRequested;
        }

        void nodeType_NodeMenuItemsRequested(object sender, ExplorerNodeMenuItemsRequestedEventArgs e)
        {
            IMenuItem menuItem = e.MenuItems.Add("Display Message");
            menuItem.Click += menuItem_Click;
        }

        void menuItem_Click(object sender, MenuItemEventArgs e)
        {
            IExplorerNode node = (IExplorerNode)e.Owner;
            MessageBox.Show(string.Format("Clicked the menu item for the '{0}' node.", node.Text));
        }
    }

    [Export(typeof(IExplorerNodeTypeExtension))]
    [ExplorerNodeType(ExtensionNodeTypes.FieldNode)]
    internal class FieldNodeExtensionWithProperty : IExplorerNodeTypeExtension
    {
        public void Initialize(IExplorerNodeType nodeType)
        {
            nodeType.NodePropertiesRequested += nodeType_NodePropertiesRequested;
        }

        void nodeType_NodePropertiesRequested(object sender, ExplorerNodePropertiesRequestedEventArgs e)
        {
            // Only add the property to "Body" fields.
            if (e.Node.Text == "Body")
            {
                ExampleProperty propertyObject;

                // If the properties object already exists for this node, get it from the node's annotations.
                if (!e.Node.Annotations.TryGetValue(out propertyObject))
                {
                    // Otherwise, create a new properties object and add it to the annotations.
                    propertyObject = new ExampleProperty(e.Node);
                    e.Node.Annotations.Add(propertyObject);
                }

                e.PropertySources.Add(propertyObject);
            }
        }
    }

    internal class ExampleProperty
    {
        private IExplorerNode node;
        private const string propertyId = "Contoso.ExampleProperty";
        private const string propertyDefaultValue = "This is an example property.";

        internal ExampleProperty(IExplorerNode node)
        {
            this.node = node;
        }

        // Gets or sets a simple string property. 
        [DisplayName("ContosoExampleProperty")]
        [DescriptionAttribute("This is an example property for field nodes.")]
        [DefaultValue(propertyDefaultValue)]
        public string TestProperty
        {
            get
            {
                string propertyValue;

                // Get the current property value if it already exists; otherwise, return a default value.
                if (!node.Annotations.TryGetValue(propertyId, out propertyValue))
                {
                    propertyValue = propertyDefaultValue;
                }
                return propertyValue;
            }
            set
            {
                if (value != propertyDefaultValue)
                {
                    // Store the property value in the Annotations property of the node. 
                    // Data in the Annotations property does not persist when Visual Studio exits.
                    node.Annotations[propertyId] = value;
                }
                else
                {
                    // Do not save the default value.
                    node.Annotations.Remove(propertyId);
                }
            }
        }
    }

}

이 확장은 편집 가능한 문자열 속성을 노드에 추가합니다. 또한 SharePoint 서버의 읽기 전용 데이터를 표시하는 사용자 지정 속성을 만들 수도 있습니다. 이 작업을 수행하는 방법을 보여 주는 예제를 보려면 연습: 서버 탐색기를 확장하여 웹 파트 표시를 참조하십시오.

코드 컴파일

이 예제에는 다음 어셈블리에 대한 참조가 필요합니다.

  • Microsoft.VisualStudio.SharePoint

  • Microsoft.VisualStudio.SharePoint.Explorer.Extensions

  • System.ComponentModel.Composition

  • System.Windows.Forms

확장 배포

서버 탐색기 확장을 배포하려면 어셈블리 및 확장과 함께 배포할 다른 모든 파일에 대한 VSIX(Visual Studio Extension) 패키지를 만듭니다. 자세한 내용은 Visual Studio에서 SharePoint 도구에 대한 확장 배포를 참조하십시오.

참고 항목

작업

방법: 서버 탐색기에 사용자 지정 SharePoint 노드 추가

연습: 서버 탐색기를 확장하여 웹 파트 표시

기타 리소스

서버 탐색기에서 SharePoint 연결 노드 확장

SharePoint 도구 확장과 사용자 지정 데이터 연결