将Web部件添加到站点定义

时间:2012-04-02 10:35:58

标签: sharepoint sharepoint-2010

我创建了一个自定义sitedefinition。在我的sitedefition中,我想激活一个自定义功能(我将guid添加到我的onet.xml中)。

将webpart添加到页面的自定义功能是创建错误。错误是default.aspx未找到。我以为首先创建了sitedefition中的页面。之后该功能将被激活。为什么我收到错误?

SPLimitedWebPartManager collWebParts =  web.GetLimitedWebPartManager("default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

collWebParts.AddWebPart(CustomWebPart, "MainLeft", 1);
collWebParts.SaveChanges(CustomWebPart);
collWebParts.Web.Dispose();

1 个答案:

答案 0 :(得分:2)

您最好在onet.xml中的模块中添加webparts。只需添加标记并使用标记来配置您的特定网站部分。

一个简单的样本:

<Modules>
    <Module Name="DefaultBlank" Url="" Path="">
      <File Url="default.aspx" Path="default.aspx">
        <AllUsersWebPart WebPartOrder="0" WebPartZoneID="Right" ID="g_bdef0b56_c2f4_4c5a_bc39_2908a0f61410">
        <![CDATA[<webParts>
        <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
          <metaData>
            <type name="***.LatestDiscussionsWebPart.LatestDiscussionsWebPart, ***, Version=1.0.0.0, Culture=neutral, PublicKeyToken=20cca094e7d0240a" />
            <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
          </metaData>
          <data>
            <properties>
              <property name="AllowZoneChange" type="bool">True</property>
              <property name="ExportMode" type="exportmode">All</property>
              <property name="HelpUrl" type="string" />
              <property name="Hidden" type="bool">False</property>
              <property name="TitleUrl" type="string" />
              <property name="Description" type="string">Latest Discussions WebPart</property>
              <property name="AllowHide" type="bool">True</property>
              <property name="AllowMinimize" type="bool">True</property>
              <property name="Title" type="string">Latest Discussions </property>
              <property name="ChromeType" type="chrometype">Default</property>
              <property name="AllowConnect" type="bool">True</property>
              <property name="Width" type="unit" />
              <property name="Height" type="unit" />
              <property name="HelpMode" type="helpmode">Navigate</property>
              <property name="CatalogIconImageUrl" type="string" />
              <property name="AllowEdit" type="bool">True</property>
              <property name="TitleIconImageUrl" type="string" />
              <property name="Direction" type="direction">NotSet</property>
              <property name="AllowClose" type="bool">True</property>
              <property name="ChromeState" type="chromestate">Normal</property>
            </properties>
          </data>
        </webPart>
      </webParts>]]>
        </AllUsersWebPart>
      </File>
</Module>
祝你好运。