如何解决SharePoint 2010:重新部署功能将重复的Web部件添加到页面中
|| 我将发布页面配置为功能的一部分,并在页面上放置一个列表视图Web部件(请参见下面的代码)。所有这些都能完美地发挥作用。<Elements>
<Module>
<File Path=\"default.aspx\" Url=\"BulletinBoard.aspx\" Type=\"GhostableInLibrary\" IgnoreIfAlreadyExists=\"TRUE\">
<Property Name=\"Title\" Value=\"Bulletin Board\" />
<Property Name=\"PublishingPageLayout\" Value=\"~SiteCollection/_catalogs/masterpage/ListNewsletterStyle.aspx\" />
<Property Name=\"ContentType\" Value=\"Page\" />
<Property Name=\"PublishingPageImage\" Value=\"\" />
<View List=\"Lists/BulletinBoard\" BaseViewID=\"2\" WebPartZoneID=\"Main\" WebPartOrder=\"1\">
<![CDATA[
<webParts>
<webPart xmlns=\"http://schemas.microsoft.com/WebPart/v3\">
<metaData>
<type name=\"Microsoft.SharePoint.WebPartPages.XsltListViewWebPart,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c\" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name=\"Title\">Active Announcements</property>
<property name=\"ChromeType\">None</property>
</properties>
</data>
</webPart>
</webParts>
]]>
</View>
</File>
</Module>
</Elements>
唯一的问题是,每次我通过Visual Studio重新部署功能时,都会复制列表视图Web部件(即,将另一个添加到Web部件区域)。
此问题似乎只影响带有解决方法
您可以添加功能接收器并添加webpart(如果不存在),而不是以XML形式添加webpart。
标签是什么意思?
,从Waldek Mastykarz中查看此博客条目。它下面的C#代码应与您所寻找的相似。
using (SPSite site = new SPSite(\"http://sharepoint\"))
{
SPList list = site.GetCatalog(SPListTemplateType.MasterPageCatalog);
SPListItemCollection items = list.Items;
List<string> webParts = new List<string>();
// find the right Page Layout
foreach (SPListItem item in items)
{
if (item.Name.Equals(\"CustomPageLayout.aspx\",StringComparison.CurrentCultureIgnoreCase))
{
SPFile file = item.File;
// get the Web Part Manager for the Page Layout
SPLimitedWebPartManager wpm =
file.GetLimitedWebPartManager(PersonalizationScope.Shared);
// iterate through all Web Parts and remove duplicates
while (wpm.WebParts.Count > 0)
{
StringBuilder sb = new StringBuilder();
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
XmlWriter xw = XmlWriter.Create(sb,xws);
System.Web.UI.WebControls.WebParts.WebPart wp =
wpm.WebParts[0];
wpm.ExportWebPart(wp,xw);
xw.Flush();
string md5Hash = getMd5Hash(sb.ToString());
if (webParts.Contains(md5Hash))
wpm.DeleteWebPart(wp);
else
webParts.Add(md5Hash);
}
}
}
}
,SharePoint 2013用户注意事项。您应该在标签中添加ReplaceContent = True。重复的Webpart问题将得到解决。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。