2009-10-17 73 views
0

我想在使用CAML的SharePoint功能中創建一個列表模板。我有兩個內容類型「新聞」和「新聞發佈」它們共用的兩個字段名爲概述說明Sharepoint ListTemplate多種內容類型 - 參考字段

我一直在閱讀「listtemplate」caml元素不會自動添加內容類型的字段,您需要指定所有字段。指定字段時SharePoint不會更新共享點列表設置(screenshot)中的「已使用」。 這是一個問題,因爲無法使用這些字段更新視圖。

這可以解決用c#編寫的功能接收器?

任何想法?

<?xml version="1.0" encoding="utf-8" ?> 
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> 
    <ListTemplate Name="News" 
       DisplayName="News" 
       Description="News" 
       Type="100" 
       BaseType="0" 
       OnQuickLaunch="true" 
       SecurityBits="11" 
       Sequence="410" 
       Image="/_layouts/images/itgen.gif" 
       Unique="True" 
       DisableAttachments="True" /> 
</Elements> 

<?xml version="1.0" encoding="utf-8" ?> 
<List Name="News" 
     Title="News" 
     FolderCreation="FALSE" 
     Direction="$Resources:Direction;" 
     Url="Lists/News" 
     EnableContentTypes="True" 
     BaseType="0" 
     Type="100" 
     xmlns="http://schemas.microsoft.com/sharepoint/" 
     xmlns:ows="Microsoft SharePoint"> 
    <MetaData> 
    <ContentTypes> 
     <ContentTypeRef ID="0x010007196C9EB6E5B04BAE108FD1969FD42B01" /> 
     <ContentTypeRef ID="0x010007196C9EB6E5B04BAE108FD1969FD42B02" /> 
    </ContentTypes> 
    <Fields> 
     <Field ID="{1E061768-0380-48e4-8E71-86CAE6DDDF30}" Type="Note" DisplayName="Overview" Name="Overviews" /> 
     <Field ID="{9406510E-511A-438f-AD9F-A55CED16B033}" Type="Note" DisplayName="Description" StaticName="Description" Name="Description" /> 
    </Fields> 
    <View> 
     Removed For Post 
    </View>   
    <Forms> 
     <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> 
     <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> 
     <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> 
    </Forms> 
    </MetaData> 
</List> 

回答

1

這是具有CAML爲你做初始化的問題之一,我總是對代碼做的事情,如果可能的話:)

我也有類似的問題,有一天,結束了去除ContentTypeRef部分,讓它只從item中繼承,並在創建列表的特性接收器中繼承,添加我想要的內容類型,然後刪除項目內容類型。這樣的清單,從內容類型

繼領域的正確填充是我的功能接收器:

public void CreateList(SPFeatureReceiverProperties prop) 
     { 
      logger.Info("Creating list"); 
      using (SPWeb currentWeb = WebHelper.GetWeb(prop)) 
      { 
       try 
       { 
        SPList list = ListHelper.CreateList("Other Documents", "", "Rhb Other Documents List", true, currentWeb); 
        logger.Info("List created successfully"); 

        logger.Info("Attaching content types"); 
        list.ContentTypesEnabled = true; 
        list.Update(); 
        list.ContentTypes.Add(currentWeb.ContentTypes["RhbOtherDocuments"]); 
        list.Update(); 
        list.ContentTypes["Item"].Delete(); 
        list.Update(); 
        logger.Info("Content type attached"); 
       } 
       catch (Exception e) 
       { 
        logger.Error("List creation failed", e); 
        Console.WriteLine(e); 
       } 
      } 
     } 

在功能接收器中使用的網絡輔助類:

public class WebHelper 
    { 
     #region Helper functions 
     public static SPWeb GetWeb(SPFeatureReceiverProperties prop) 
     { 
      using (SPSite site = prop.Feature.Parent as SPSite) 
      { 
       return site != null ? site.RootWeb : prop.Feature.Parent as SPWeb; 
      } 
     } 
     #endregion 
    } 

名單幫手在功能接收器中使用的類:

public static SPList CreateList(string ListName, string description, string templateName, bool Visible, 
             SPWeb web) 
     { 
      SPListTemplate template = web.Site.RootWeb.ListTemplates[templateName]; 
      SPList list = web.Lists[web.Lists.Add(ListName, description, template)]; 
      list.EnableVersioning = false; 
      list.EnableAttachments = false; 
      list.OnQuickLaunch = false; 
      list.EnableFolderCreation = false; 
      list.Update(); 
      return list; 
     } 

n的一件事請注意,這種機制可能比通過CAML更好,因爲這樣我們不必在內容類型和列表中都維護字段信息。我最初發現一篇文章(see here),它提供了大部分內容我的解決方案。

相關問題