简体   繁体   English

更改自定义列表模板时更新列表

[英]Update lists when changing custom list template

I have created a feature, a publishing site, in Visual Studio to MOSS - this feature contains some custom list templates and some lists using the template definitions. 我已经在Visual Studio到MOSS中创建了一个功能,一个发布站点-此功能包含一些自定义列表模板和一些使用模板定义的列表。 Now I need to update the list templates, which is not a problem as it is just adding af few lines to my schema.xml, but I need a way to reflect the update on the existing lists also. 现在,我需要更新列表模板,这不是问题,因为它只是向我的schema.xml添加了几行,但是我还需要一种方法来在现有列表上反映更新。

As far as i know this feature is not standard Sharepoint, but how can I programatically work around this eg ny in my OnActivated, loop through my list and update (delete/add) the fields based on the template of the list? 据我所知,该功能不是标准的Sharepoint,但是如何在OnActivated中以编程方式解决此问题(例如ny),遍历列表并根据列表模板更新(删除/添加)字段?

Yes, when you update list schema, it will not reflect in already created list. 是的,当您更新列表架构时,它不会反映在已经创建的列表中。 For this, add a FeatureActivated event handler in your schema. 为此,在您的模式中添加FeatureActivated事件处理程序。 This event handler will run a code whenever you activate your feature. 每当您激活功能时,此事件处理程序都会运行代码。

Create a XML configuration file in your Feature which will contain the list names which are already created. 在功能中创建一个XML配置文件,其中将包含已创建的列表名称。 The code will then read the XML file and update your lists which are already created. 然后,代码将读取XML文件并更新您已创建的列表。

For extensibility and flexibility, Note that this code needs to be as defensive as possible. 为了可扩展性和灵活性,请注意,此代码必须尽可能具有防御性。 For ex , when you again activate the feature again sometime in future it should not make the change again resulting in loss or duplicacy of changes. 例如,当您将来某时再次激活该功能时,不应再次进行更改,否则会导致更改丢失或重复。 It should first check and then only make the change. 它应该首先检查,然后才进行更改。

The same scheme can be used for content types. 相同的方案可以用于内容类型。 If required I can post a code snippet for you. 如果需要,我可以为您发布一个代码段。

 public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        try
        {
            // Fix the Article Date column
            if (properties != null)
            {
                FixArticleDate(properties);
            }

            // Fix Metadata Tagging site columns by setting CustomField "MetadataType" to the Default value set in the field definition manifest file.
            if (properties != null && properties.Feature.Properties["FixMetadataTagging"] != null)
            {
                RepairMetadataTaggingSiteColumns(properties);
            }

            // Fix Lookup site columns by retrieving lookup list GUID from List="url". 
            if (properties != null && properties.Feature.Properties["FixListTagging"] != null)
            {
                RepairListTaggingSiteColumns(properties);
            }

            // Fixing Site Columns
            if (properties != null && properties.Feature.Properties["FixSiteColumns"] != null)
            {
                RepairSiteColumns(properties);
            }
        }
        catch (SPException sharepointEx)
        {
            ExceptionManager.LogError(ULSTracerCategoriesEnum.FeatureReceivers, sharepointEx);
        }
    }

XML: XML:

<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="A23990CF-C35D-4771-BF5A-916C304C9EF9"
   Title="Content Types"
   Description="This Feature Creates all the Required Content Types and site columns"
   Version="1.0.0.0" Scope="Site" Hidden="FALSE"
   ReceiverAssembly="xxxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=86597c5d57921943"
   ReceiverClass="xxxx.SharePoint.UI.Core.FeatureReceivers.CoreFeatureReceiver"        
   xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="SiteColumns\SiteColumns.xml" />
    <ElementManifest Location="ContentTypes\ContentTypes.xml" />
  </ElementManifests>
  <Properties>
    <Property Key="FixMetadataTagging" Value="SiteColumns\MetadataTaggingSiteColumnsManifest.xml"/>
    <Property Key="FixListTagging" Value="SiteColumns\ListTaggingSiteColumnsManifest.xml"/>
    <Property Key="FixSiteColumns" Value="ContentTypeFixes\SiteColumnAdditions.xml"/>
  </Properties>
</Feature>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WSS 3.0-无法使用Web服务显示创建的自定义模板列表 - WSS 3.0 - Can not display created custom template lists with web services 如何更新SharePoint功能(列出模板视图) - How to Update SharePoint feature (List Template Views) 自定义事件列表模板的ListViewWebPart问题 - ListViewWebPart problem with custom Event list template SharePoint:用于特定列表视图的自定义警报模板 - SharePoint: Custom alert template for a specific list view 列表之间的SharePoint 2010关系-与引用自定义列表列的区别 - SharePoint 2010 Relationships between lists - difference with referencing custom list column 从使用功能创建的CUstom列表中导出列表模板 - Exporting List Template from the CUstom List created using a Feature 使用特权提升更新SharePoint列表,而无需更改“修改者”字段数据 - Update a SharePoint list with Elevated Privileges without changing Modified By field data SharePoint Online Powershell CSOM从自定义模板创建列表 - SharePoint Online Powershell CSOM create list from custom template 在共享点功能中导入2个自定义列表,第二个列表具有与第一个相同的自定义字段 - Importing 2 custom lists in a sharepoint feature, 2nd list taking on the same custom fields as the first 如何将自定义列添加到现有的WSS列表模板 - How do I add custom column to existing WSS list template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM