サーバー エクスプローラーの組み込みの SharePoint ノードごとに、そのノードが表す SharePoint コンポーネント (基になるコンポーネント) のデータを取得できます。 詳細については、「サーバー エクスプローラーの [SharePoint 接続] ノードの拡張」を参照してください。
例
次のコード例は、サーバー エクスプローラーでリスト ノードが表す SharePoint リスト (基になるリスト) のデータを取得する方法を示しています。 既定では、リスト ノードには [ブラウザーで表示] コンテキスト メニュー項目があり、この項目をクリックすると、Web ブラウザーでリストを開くことができます。 この例では、Visual Studio でリストを直接開く [Visual Studio で表示] コンテキスト メニュー項目を追加して、リスト ノードを拡張します。 また、ノードのリスト データにアクセスして、Visual Studio で開くリストの URL を取得します。
Imports System.ComponentModel.Composition
Imports Microsoft.VisualStudio.SharePoint
Imports Microsoft.VisualStudio.SharePoint.Explorer
Imports Microsoft.VisualStudio.SharePoint.Explorer.Extensions
Namespace Contoso.ServerExplorerExtension
<Export(GetType(IExplorerNodeTypeExtension))> _
<ExplorerNodeType(ExtensionNodeTypes.ListNode)> _
Friend Class ListNodeExtension
Implements IExplorerNodeTypeExtension
Private projectService As ISharePointProjectService
Private dteObject As EnvDTE.DTE
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("View in Visual Studio")
AddHandler menuItem.Click, AddressOf MenuItemClick
End Sub
Private Sub MenuItemClick(ByVal Sender As Object, ByVal e As MenuItemEventArgs)
' Get the data for the list node.
Dim node As IExplorerNode = CType(e.Owner, IExplorerNode)
Dim nodeInfo As IListNodeInfo = node.Annotations.GetValue(Of IListNodeInfo)()
If dteObject Is Nothing Then
If projectService Is Nothing Then
projectService = CType(node.ServiceProvider.GetService(GetType(ISharePointProjectService)),
ISharePointProjectService)
End If
dteObject = CType(projectService.ServiceProvider.GetService(GetType(EnvDTE.DTE)), EnvDTE.DTE)
End If
dteObject.ItemOperations.Navigate(nodeInfo.DefaultViewUrl.ToString(),
EnvDTE.vsNavigateOptions.vsNavigateOptionsNewWindow)
End Sub
End Class
End Namespace
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.SharePoint;
using Microsoft.VisualStudio.SharePoint.Explorer;
using Microsoft.VisualStudio.SharePoint.Explorer.Extensions;
namespace Contoso.ServerExplorerExtension
{
[Export(typeof(IExplorerNodeTypeExtension))]
[ExplorerNodeType(ExtensionNodeTypes.ListNode)]
internal class ListNodeExtension : IExplorerNodeTypeExtension
{
private ISharePointProjectService projectService;
private EnvDTE.DTE dteObject;
public void Initialize(IExplorerNodeType nodeType)
{
nodeType.NodeMenuItemsRequested += nodeType_NodeMenuItemsRequested;
}
void nodeType_NodeMenuItemsRequested(object sender, ExplorerNodeMenuItemsRequestedEventArgs e)
{
IMenuItem menuItem = e.MenuItems.Add("View in Visual Studio");
menuItem.Click += menuItem_Click;
}
void menuItem_Click(object sender, MenuItemEventArgs e)
{
// Get the data for the list node.
IExplorerNode node = (IExplorerNode)e.Owner;
IListNodeInfo nodeInfo = node.Annotations.GetValue<IListNodeInfo>();
if (dteObject == null)
{
if (projectService == null)
{
projectService = (ISharePointProjectService)node.ServiceProvider.GetService(
typeof(ISharePointProjectService));
}
dteObject = (EnvDTE.DTE)projectService.ServiceProvider.GetService(typeof(EnvDTE.DTE));
}
dteObject.ItemOperations.Navigate(nodeInfo.DefaultViewUrl.ToString(),
EnvDTE.vsNavigateOptions.vsNavigateOptionsNewWindow);
}
}
}
この例では、SharePoint プロジェクト サービスを使用して、Visual Studio でリストを開くために使用する DTE オブジェクトを取得します。 SharePoint プロジェクト サービスの詳細については、「SharePoint プロジェクト サービスの使用」を参照してください。
SharePoint ノードの拡張機能を作成する場合の基本的な作業の詳細については、「方法: サーバー エクスプローラーの SharePoint ノードを拡張する」を参照してください。
コードのコンパイル
この例は、次のアセンブリへの参照を必要とします。
EnvDTE
Microsoft.VisualStudio.SharePoint
Microsoft.VisualStudio.SharePoint.Explorer.Extensions
System.ComponentModel.Composition
拡張機能の配置
サーバー エクスプローラーの拡張機能を配置するには、同梱する必要のあるアセンブリや各種ファイルの Visual Studio Extension (VSIX) パッケージを作成します。 詳細については、「Visual Studio での SharePoint ツールの拡張機能の配置」を参照してください。
参照
概念
サーバー エクスプローラーの [SharePoint 接続] ノードの拡張