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

发布于 2024-10-11 12:48:16 字数 237 浏览 3 评论 0原文

我在 Visual Studio 中创建了一个功能,即发布网站到 MOSS - 此功能包含一些自定义列表模板和一些使用模板定义的列表。现在我需要更新列表模板,这不是问题,因为它只是向我的 schema.xml 添加几行,但我还需要一种方法来反映现有列表的更新。

据我所知,这个功能不是标准的 Sharepoint,但是我如何以编程方式解决这个问题,例如在我的 OnActivated 中,循环遍历我的列表并根据列表的模板更新(删除/添加)字段?

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

As far as i know this feature is not standard Sharepoint, but how can I programatically work around this e.g. ny in my OnActivated, loop through my list and update (delete/add) the fields based on the template of the list?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揽月 2024-10-18 12:48:16

是的,当您更新列表架构时,它不会反映在已创建的列表中。为此,请在您的架构中添加一个 FeatureActivated 事件处理程序。每当您激活功能时,此事件处理程序都会运行代码。

在您的功能中创建一个 XML 配置文件,其中将包含已创建的列表名称。然后,代码将读取 XML 文件并更新已创建的列表。

为了可扩展性和灵活性,请注意此代码需要尽可能具有防御性。例如,当您将来某个时候再次激活该功能时,它不应该再次进行更改,从而导致更改丢失或重复。它应该首先检查,然后才进行更改。

相同的方案可用于内容类型。如果需要,我可以为您发布代码片段。

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

Yes, when you update list schema, it will not reflect in already created list. For this, add a FeatureActivated event handler in your schema. 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. The code will then read the XML file and update your lists which are already created.

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 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文