设为首页 收藏本站
查看: 1179|回复: 0

[经验分享] MOSS 2010:Visual Studio 2010开发体验(11)——扩展SharePoint Explorer

[复制链接]

尚未签到

发表于 2015-9-24 10:14:57 | 显示全部楼层 |阅读模式
  关于SharePoint Explorer,是VS2010的一个新特性,可以让开发人员很方便地浏览到SharePoint站点的结构,并且做一些简单事情
  我在下面这篇文章中已经做过一些介绍
  http://www.cnblogs.com/chenxizhang/archive/2010/04/05/1704680.html
  上文中,我已经提到了,这个工具我认为还不是很完善。但它确实留出了定制的空间。那么今天我们就来试一下吧
  为什么我会想做这个事情呢,就是因为我在本系列的第10篇中提到了内容类型的开发,我们需要查看某个内容类型的定义的话,比较费劲,需要特意去写代码。所以我就想,如果直接在这个Explorer中能做这个工作,当然比较好。然后就手痒无比,马上动手做了起来。
  
  1. 首先来看一下SharePoint Explorer的样子,它实际上是Server Explorer的一个插件
DSC0000.png
  2. 好吧,我们如何开始来做扩展呢?
  先想清楚吧,我们希望在ContentType上面有一个快捷菜单,然后点击之后,可以查看到它的属性吧。应该还是比较简单的
  下面这个链接中有比较清楚的介绍,我今天基本上是依葫芦画瓢了
  http://msdn.microsoft.com/en-us/library/ee471438(VS.100).aspx
  
  大致的步骤如下,我做了一个简单的翻译
To extend a SharePoint node in Server Explorer

  •   Create a class library project.(创建一个类库项目)

  •   Add references to the following assemblies:(添加如下的引用)

    •   Microsoft.VisualStudio.SharePoint
    •   Microsoft.VisualStudio.SharePoint.Explorer.Extensions
    •   System.ComponentModel.Composition

  •   Create a class that implements the IExplorerNodeTypeExtension interface.(创建一个类,继承一个接口)
  •   Add the System.ComponentModel.Composition.ExportAttribute attribute to the class. This attribute enables Visual Studio to discover and load your IExplorerNodeTypeExtension implementation. Pass the IExplorerNodeTypeExtension type to the attribute constructor.(添加一个Attribute)

  •   Add the ExplorerNodeTypeAttribute attribute to the class. This attribute specifies the string identifier for the type of node that you want to extend.
      To specify built-in node types provided by Visual Studio, pass one of the following enumeration values to the attribute constructor:

    •   ExplorerNodeTypes: Use these values to specify site connection nodes (the nodes that display site URLs), site nodes, or all other parent nodes in Server Explorer.
    •   ExtensionNodeTypes: Use these values to specify one of the built-in nodes that represent an individual component on a SharePoint site, such as a node that represents a list, field, or content type.(继续添加Attribute)


  •   In your implementation of the IExplorerNodeTypeExtension.Initialize method, use members of the nodeType parameter to add features to the node. This parameter is an IExplorerNodeType object that provides access to the events defined in the IExplorerNodeEvents interface. For example, you can handle the following events:

    •   IExplorerNodeEvents.NodeChildrenRequested: Handle this event to add new child nodes to the node. For more information, see How to: Add a Custom SharePoint Node to Server Explorer.
    •   IExplorerNodeEvents.NodeMenuItemsRequested: Handle this event to add a custom shortcut menu item to the node.
    •   IExplorerNodeEvents.NodePropertiesRequested: Handle this event to add custom properties to the node. The properties appear in the Properties window when the node is selected.


  
  那我们还等什么呢?
DSC0001.png
  将默认的类型名称修改为ContentTypeNodeExtension
DSC0002.png
  【注意】需要确认框架版本为.NET Framework 4.0
DSC0003.png
  
  添加引用
DSC0004.png
DSC0005.png
DSC0006.png
  3.修改一些简单代码using System;
using Microsoft.VisualStudio.SharePoint.Explorer;
using Microsoft.VisualStudio.SharePoint.Explorer.Extensions;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.SharePoint;
using System.Windows.Forms;

namespace Xizhang.ServerExplorerExtension
{
[Export(typeof(IExplorerNodeTypeExtension))]
[ExplorerNodeType(ExtensionNodeTypes.ContentTypeNode)]
public class ContentTypeNodeExtension : IExplorerNodeTypeExtension
{
public void Initialize(IExplorerNodeType nodeType)
{
System.IO.File.AppendAllText("c:\\log.txt",DateTime.Now.ToString());
nodeType.NodeMenuItemsRequested += new EventHandler<ExplorerNodeMenuItemsRequestedEventArgs>(nodeType_NodeMenuItemsRequested);
}
void nodeType_NodeMenuItemsRequested(object sender, ExplorerNodeMenuItemsRequestedEventArgs e)
{
IMenuItem menuItem = e.MenuItems.Add("我的菜单");
menuItem.Click += new EventHandler<MenuItemEventArgs>(menuItem_Click);
}
void menuItem_Click(object sender, MenuItemEventArgs e)
{
IExplorerNode node = (IExplorerNode)e.Owner;
MessageBox.Show(string.Format("你点击了 '{0}' 节点,类型是'{1}'.", node.Text,node.NodeType.Name));
}
}
}

DSC0007.png 4. 部署该扩展详细的步骤可以参考http://msdn.microsoft.com/en-us/library/ee513825.aspx更加详细的一个介绍http://msdn.microsoft.com/en-us/library/dd393694(v=VS.100).aspx 简单来说,我们需要创建一个所谓VSIX的项目来定义部署的信息,不过在此之前,你需要安装VS2010 SDKhttp://www.microsoft.com/downloads/details.aspx?familyid=4659F71D-4E58-4DCD-B755-127539E21147&displaylang=en DSC0008.png
DSC0009.png DSC00010.png DSC00011.png DSC00012.png DSC00013.png DSC00014.png DSC00015.png

  切换到全屏幕
DSC00016.png
  点击“Add Content”
DSC00017.png
  设置好之后,就可以编译该项目了。(以前我们要做一个VS的扩展包可远远没这么方便)
  ------ Rebuild All started: Project: Xizhang.ServerExplorerExtension, Configuration: Debug Any CPU ------
  Xizhang.ServerExplorerExtension -> C:\Users\Administrator\Documents\Visual Studio 2010\Projects\OrderListSolution\Xizhang.ServerExplorerExtension\bin\Debug\Xizhang.ServerExplorerExtension.dll
------ Rebuild All started: Project: Xizhang.ServerExplorer.Extension.Package, Configuration: Debug Any CPU ------
  Xizhang.ServerExplorer.Extension.Package ->
  Xizhang.ServerExplorer.Extension.Package ->
  Xizhang.ServerExplorer.Extension.Package -> C:\Users\Administrator\Documents\Visual Studio 2010\Projects\OrderListSolution\Xizhang.ServerExplorer.Extension.Package\bin\Debug\Xizhang.ServerExplorer.Extension.Package.dll
  Creating intermediate PkgDef file.
  Creating VSIX Container...
  Xizhang.ServerExplorer.Extension.Package -> C:\Users\Administrator\Documents\Visual Studio 2010\Projects\OrderListSolution\Xizhang.ServerExplorer.Extension.Package\bin\Debug\Xizhang.ServerExplorer.Extension.Package.vsix
  Setting up Visual Studio for debugging extensions. This one-time operation may take a minute or more.
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========
  【注意】它生成了一个vsix文件
DSC00018.png
  5.安装该扩展
  双击vsix文件
DSC00019.png
DSC00020.png
  6. 使用该扩展。重新打开Visual Studio,可以通过Extension Manager看到我们安装好的扩展包
DSC00021.png
DSC00022.png
  激动人心的时刻到了
DSC00023.png
  我们可以点击“我的菜单”
DSC00024.png
  到这里为止,我们这个扩展程序就实现了,如果你有兴趣,请将它修改得更加实用些吧

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-118079-1-1.html 上篇帖子: MOSS 2010:Visual Studio 2010开发体验(11)——扩展SharePoint Explorer 下篇帖子: SharePoint 2013 工作流之使用Visio设计篇
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表