2011-04-13 2 views
4

게시 페이지를 기능의 일부로 제공하고 단일 목록보기 웹 파트를 페이지에 배치합니다 (아래 코드 참조). 이 모든 것이 완벽하게 작동합니다.SharePoint 2010 : 중복 적용 기능을 페이지에 추가합니다.

<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를 통해 내 기능을 재배치 때마다, 목록보기 웹 파트 (즉, 다른 하나는 웹 파트 영역에 추가됩니다) 중복된다는 점이다.

이 문제 만 은 <보기 ... > 태그가있는 웹 부품에 영향을 미치기 위해으로 표시됩니다. < AllUsersWebPart ... > 태그가 제공된 웹 파트가 복제되지 않습니다.

어떻게 방지합니까?

답변

3

XML에서 웹 파트를 추가하는 대신 피처 수신기를 추가하고 추가하지 않을 경우 추가 할 수 있습니다. 태그 란 무엇입니까?

+0

Anita님께 감사드립니다. 필자는 일관성을 위해 모든 페이지와 웹 파트를 동일한 장소 (기능 XML을 통해)에 제공하기를 원했지만 기능 수신자를 사용하여 중복 된 부분을 확인하고 필요한 경우 제거 할 수있었습니다. "태그"참조에 대해서는 StackOverFlow가 내 HTML 마크 업을 게시물에 포함시키지 않았습니다. 위의 업데이트를 참조하십시오. –

1

Waldek Mastykarz의 blog entry을 확인하십시오. 그것은 당신이 찾고있는 것과 유사해야합니다 아래의 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); 
     } 
    } 
    } 
} 
+0

필자의 경우, 피처 수신자를 사용하여 비활성화시 피처에 의해 입증 된 웹 파트를 삭제했습니다. 이 기능을 다시 활성화하면 (예 : 개발 중에 Visual Studio에서 다시 배포 할 때) 새 웹 파트에 대한 "제거 된"방법입니다. 이 기능을 구현 한 매니페스트를 분석하고 제공된 모든 웹 파트 인스턴스를 제거한 위대한 Linq 코드를 발견했습니다. 따라서 하드 코드 된 페이지 레이아웃 이름 등이 없었습니다. 그리고 웹 파트가 개인화되지 않았기 때문에 사용자의 변경 사항이 없었습니다/웹 파트를 삭제할 때 손실 될 설정. –

+0

당신은 그 코드에 대한 조언자가 있습니까? 위와 비슷한 코드를 피처 수신기에서 실행하지만 솔루션이 더 완벽하게 들립니다. – skeletank

+0

[업데이트] 이것은 내가 사용한 블로그 게시물입니다. http://platinumdogs.wordpress.com/2009/08/10/removing-provisioned-files-from-sharepoint-during-feature-deactivation/ –

0

SharePoint 2013 사용자 참고 사항. ReplaceContent = True를 태그에 추가해야합니다. 중복 된 웹 파트 문제가 해결됩니다.

관련 문제