【问题标题】:Deploy Web part as a feature将 Web 部件部署为功能
【发布时间】:2010-12-19 19:38:53
【问题描述】:
我有一个 web 部件 dashboard.cs,它根据列表中的记录呈现一些 HTML。不,我创建了一个站点定义。我想将此 Web 部件作为一项功能集成到我的站点定义中,因此当我在 install.bat 的帮助下构建项目时,我想安装此功能,该功能将在相应站点上部署此 Web 部件。现在,当我转到站点设置->站点功能时,必须在此处列出此功能,一旦我安装此功能,当我在编辑模式下切换页面并单击添加 Web 部件按钮时,我的 Web 部件将被填充。
谁能帮帮我..?
提前致谢
萨钦
【问题讨论】:
标签:
sharepoint
wss
web-parts
【解决方案1】:
在您的站点定义的 onet.xml 文件中,请务必在 SiteFeatures/WebFeatures 部分下包含您的功能,如下所示:
<SiteFeatures>
<Feature ID="01D547B0-4C63-42d1-A7F9-4D34ACC4E718" />
</SiteFeatures>
<WebFeatures>
<Feature ID="657793AB-D427-4141-879C-BCFB6852B619" />
</WebFeatures>
如果您的功能是网站集功能,则它位于 SiteFeatures 下。如果它是一个站点功能,那么它会在 WebFeatures 下。现在,要将 webpart 的实例自动添加到 webpart 页面,您将编辑 webpart 部署功能的 elements.xml(元素清单文件),并将 webpart 实例的标记嵌入 <![CDATA[ 标记中,如下所示:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="HCPracticePortalWebPartPages" List="101" Url="Portal Pages">
<File Url="BlankPortalPage.aspx" Name="NewPage.aspx" Type="GhostableInLibrary">
<AllUsersWebPart WebPartZoneID="Top" WebPartOrder="1"><![CDATA[
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" xmlns:iwp="http://schemas.microsoft.com/WebPart/v2/Image">
<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ImageWebPart</TypeName>
<FrameType>None</FrameType>
<Title>$Resources:wp_SiteImage;</Title>
<iwp:ImageLink>/_layouts/images/homepage.gif</iwp:ImageLink>
<iwp:AlternativeText>$Resources:core,sitelogo_wss;</iwp:AlternativeText>
</WebPart>]]>
</AllUsersWebPart>
</File>
</Module>
</Elements>
上述标记是从Using Features to Deploy Web Part Pages in WSS 慷慨借用的。我希望这会有所帮助。