0

Visual StudioからMOSSへの機能である公開サイトを作成しました。この機能には、いくつかのカスタムリストテンプレートと、テンプレート定義を使用したいくつかのリストが含まれています。次に、リストテンプレートを更新する必要があります。これは、schema.xmlに数行追加するだけなので問題ありませんが、既存のリストにも更新を反映する方法が必要です。

この機能が標準のSharepointではないことを知っている限り、プログラムでこれを回避するにはどうすればよいですか?たとえば、OnActivatedでnyを使用し、リストをループして、リストのテンプレートに基づいてフィールドを更新(削除/追加)しますか?

4

1 に答える 1

0

はい、リスト スキーマを更新しても、既に作成されているリストには反映されません。このため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>
于 2011-01-10T11:18:06.590 に答える