2012-04-02 46 views
1

我創建了一個自定義的sitedefinition。在我的sitedefition中,我想激活一個自定義功能(我將guid添加到我的onet.xml中)。添加webparts到sitedefinition

用於將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(); 
+0

你是如何創建default.aspx的?是否再次通過onet.xml中的功能?檢查指定的功能GUID的順序 – 2012-04-02 10:53:23

+0

default.aspx在站點定義中是標準的。 – 2012-04-02 15:13:12

回答

2

您最好在onet.xml的模塊中添加webparts。只需添加標籤並使用標籤來配置您的特定Web部件即可。

一個簡單的例子:

<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> 

好運。