惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - kasafuma

更改 Sharepoint帐户的密码 .SharePoint 2010配置PDF文件全文检索 人员选择器 sharepoint pdf文件以新窗口的方式打开 Replacing SharePoint 2010 Menu Control STSADM 命令使用大全 sharepoint站点Feature的定制与开发 以及 stsadm 常用命令 如何更改一台已经安装了SharePoint的服务器名称 转(WSS 3.0 Object Model ) sharepoint 2010安装步骤以及新特性 caml查询(转) 通过短信猫发送手机短信 数据库还原以及日志压缩 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园
Feature
kasafuma · 2011-09-28 · via 博客园 - kasafuma

本例将带领您一步一步创建一个自定义操作Feature,来在SharePoint网站范围内添加一个按钮到编辑通知窗体的工具栏。

步骤

  1. 在in Local_Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES创建一个SimpleFormToolbarButton 文件夹。
    注意
    当 您通过Windows资源管理器(右击一个文件夹,点新建,然后点文件夹)在Features目录中创建一个文件夹时,新文件夹不会继承权限。如果您将 Feature部署到该文件夹中,则在一些WSS页面中(比如网站设置或列表视图)将引发异常。您可以右键点击该新文件夹,点属性,点安全,然后点高级, 在全县标签中,选择允许父项的继承权限传播到该项及其子项。包括那些在此明确定义的项目,点确定。这样就可以修正该问题。您也可以通过命令行用md命令新 建文件夹,也能解决问题。

    在该文件夹中,创建一个 Feature.xml 文件,内容如下。
    XML

    <Feature Title="New Simple Form Toolbar Button"
    Scope
    ="Web"
    Id
    ="GUID"
    xmlns
    ="http://schemas.microsoft.com/sharepoint/">
    <ElementManifests>
    <ElementManifest Location="Elements.xml" />
    </ElementManifests>
    </Feature>

  2. 需要替换上面的 GUID 占位符。您可以运行 guidgen.exe来生产一个GUID,该命令位于 Local_Drive:\Program Files\Microsoft Visual Studio 8\Common7\Tools下。

  3. 在SimpleFormToolbarButton文件夹中创建一个Elements.xml 文件,该文件指向一个.aspx文件,如下。
    XML

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction Title="Simple"
    Sequence
    ="10"
    RegistrationType
    ="List"
    RegistrationId
    ="104"
    Location
    ="EditFormToolbar"
    Id
    ="Simple Toolbar">
    <UrlAction Url="/_layouts/SampleUrl.aspx" />
    </CustomAction>
    </Elements>

  4. 为了测试该Feature,我们创建了一个 SampleUrl.aspx 页面,输出 "Hello, world!"。将其放在 TEMPLATE\LAYOUTS 目录中.

    <html>
    <head runat="server">
    <title>Sample Page</title>
    </head>
    <body>
    <p>Hello, world!</p>
    </body>
    </html>

  5. 在命令行中,输入下列命令安装并在特定网站上激活该Feature。
    a. stsadm -o installfeature -filename SimpleFormToolbarButton\Feature.xml
    b. stsadm -o activatefeature -filename SimpleFormToolbarButton\Feature.xml -url http://Server/Site/Subsite

  6. 导航到某通知条目的编辑窗体中,试试我们新创建的按钮吧。

几乎所有的SharePoint Feature都在12\TEMPLATE\FEATURE目录下,为了创建一个新的Feature,先在该目录下创建一个新的文件夹,例如取名叫GeeksConnected。该文件夹的名字就是要创建的Feature的名字。现在几乎每个SharePoint的Feature都至少具备两个文件:feature.xml和elements.xml。其中feature.xml文件定义了Feature的基本信息;而elements.xml是一个manifest文件,该文件的名字可以根据自己的习惯来命名,在该文件中定义了Feature的行为。

下面将要讲述的是例子是在文档库(document libraries)里面的upload菜单里面添加一个功能。具体来说就是让一个用户能够扫描一个文档,并上传到任意的文档库里面。下面是Feature.xml的内容:

Id="FA8A2A07-3954-4b95-BA61-4C23EFE8564E"
Title="Scan Document"
Description="Adds uploading scanned documents functionality to document libraries"
Hidden="FALSE"
Version="1.0.0.0"
Scope="Site" >



这里有两个基本元素:Feature和ElementManifests,后者是前者的一个子结点元素。只有Id和Scope两个属性是必须的,Id是一个简单的GUID,可以利用Visual Studio 2005安装目录下的工具:Microsoft Visual Studio 8\Common7\Tools->Create GUID小工具生成一个GUID;Scope属性定义了Feature讲在哪里被激活,该属性值可以是:Farm,WebApplication,Site和Web。其它的属性Title、Description、Hidden和Version分别给新的Feature定义一个标题、描述、新的Feature是否在Feature列表中隐藏,以及版本。在这里可以出现的所有的属性将在后文中列出,稍安毋躁。

利用ElementManifests子元素结点来定义manifest文件的位置。可以添加多个ElementManifest或者ElementFile文件作为ElementManifest的子元素结点指向manifest文件的位置。但是ElementManifests元素结点并不是唯一可以添加的子结点元素。还可以利用ActivationDependencies元素定义子Feature和父Feature之间的关系。上面的例子中指向一个elements.xml文件,在该文件中,定义了该Feature的很多行为,如下所示:


Id="4F1B661D-F940-48c1-86DC-D9DAC8D7FA8D"
GroupId="UploadMenu"
location="Microsoft.SharePoint.StandardMenu"
Sequence="10"
Title="Scan Document"
Description="Scan a document and upload it to this library."
ImageUrl="_layouts/images/ApOpenThisLocation.gif">

在CustomAction元素里面添加的两个重要属性分别是:GroupId和Location。它们定义了自定义行为将出现在那个菜单或者工具条里面。所有可用的位置将在后文中列出。而Sequence属性阐述的是该条目的顺序,一个较大的数能够保证该条目出现在最后一个。其它的属性都很直观。UrlAction属性用来说明当用户点击条目的时候将发生的事件。在上例中是ScanDocument.aspx页,该文件被放在12/TEMPLATES/LAYOUTS目录下,该页是一个ASP.NET页,是预先创建好的。(如何利用VS 2005创建一个新的ASP.NET将在其它文章中说明)。

现在我们已经具备了所有需要的文件,然后我们就可以安装和激活新的Feature了。需要使用STSADM工具,这个工具可以在下面的目录中查找:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin

为了安装,需要在命令行下面执行:
Stsadm –o installfeature –filename GeeksConnected\feature.xml
为了激活新的Feature,可以通过SharePoint admin接口实现,也可以通过STSADM工具实现,后者实现的时候如下所示(在命令行中):
Stsadm –o activatefeature –name GeeksConnected –url http://
然后运行IISRESET,浏览任意一个文档库,点击Upload按钮,就可以看到下图所示的图标:

Table 1: Feature Element Attributes
Attribute Value Description
ActiveOnDefault True, False Determines whether the feature is activated when a new web application is created. Default value is True

AlwaysForceInstall True, False Used to overwrite previous versions of the feature if the feature is already installed. Default value is False

AutoActivateInCentralAdmin True, False Determines whether the feature is activated by default in Central Administration. Default value is False

Creator Text Identifies the feature creator
DefaultResourceFile Text Determines the name of the resource file for your feature

Description Text Describes the feature
Hidden True, False Determines whether the feature is visible within the Feature list

Id GUID A unique identifier for the feature
ImageUrl Text Associates an image with the feature
ImageUrlAltText Text Alternate text for the image feature
ReceiverAssembly Strong name Identifies the strong name of an assembly that will receive activation and deactivation events

ReceiverClass Class name Identifies the class name of the class that will receive activation and deactivation events

RequireResources True, False Indicates whether supporting resources are required. Default value is False

Scope Farm, WebApplication, Site, Web Determines at what scope the feature will appear and is activated at

SolutionId GUID Specifies the solutions to which the feature belongs

Title Text Title of the feature
Version Text Version of the feature

Table 2: Group IDs and Locations
Area Location Group ID
Library New menu Microsoft.SharePoint.StandardMenu NewMenu
Library Actions menu Microsoft.SharePoint.StandardMenu ActionsMenu
Library Settings menu Microsoft.SharePoint.StandardMenu SettingsMenu
Library Upload menu Microsoft.SharePoint.StandardMenu UploadMenu
Site Actions menu Microsoft.SharePoint.StandardMenu SiteActions
Site Settings, Site Collection Administration Links Microsoft.SharePoint.SiteSettings SiteCollectionAdmin
Site Settings, Site Administration Links Microsoft.SharePoint.SiteSettings SiteAdministration
Site Settings, Galleries links Microsoft.SharePoint.SiteSettings Galleries
Site Settings, Look and Feel links Microsoft.SharePoint.SiteSettings Customization
Site Settings, Users and Permissions links Microsoft.SharePoint.SiteSettings UsersAndPermissions
Site Actions menu for surveys Microsoft.SharePoint.SiteSettings ActionsMenuForSurvey
Site Settings, links for surveys Microsoft.SharePoint.SiteSettings SettingsMenuForSurvey