1

公正な警告:この質問の設定は長いので、辛抱強く私と一緒にいてください。

ソリューションパッケージには2つの機能があります。1つ目は、サイトフィールドとコンテンツタイプのセットです。これを機能Aと呼びましょう。フィールドの中には、タイプ「TaxonomyFieldType」のフィールドとタイプ「Note」(ノートフィールドの説明)の関連フィールドがあります。

<Elements ...>  
<Field ID="{956a1078-ec35-4c04-83c4-0a3742119496}" 
        Name="TaxonomyTextField" 
        Type="Note" DisplayName="Tags_0" 
        ShowInViewForms="FALSE" 
        Required="FALSE"
        Group="MyGroup"
        Hidden="TRUE"/>

<Field ID="{92BC866B-0415-45F0-B431-D4DF69C421CC}"
        Name="Tags"
        DisplayName="Custom Tags"
        Type="TaxonomyFieldType"
        ShowField="Term1033"
        Required="FALSE"
        Group="MyGroup"
        >
  <Customization>
    <ArrayOfProperty>
      <Property>
        <Name>IsPathRendered</Name>
        <Value xmlns:q7="http://www.w3.org/2001/XMLSchema" p4:type="q7:boolean" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">true</Value>
      </Property>
      <Property>
        <Name>TextField</Name>
        <Value xmlns:q6="http://www.w3.org/2001/XMLSchema" p4:type="q6:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">{956a1078-ec35-4c04-83c4-0a3742119496}</Value>
      </Property>
    </ArrayOfProperty>
  </Customization>
</Field>
</Elements>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Parent ContentType: Item (0x01) -->
  <ContentType ID="0x0100b61c774f4c0e4a89bf230cbb44cd4f75"
               Name="MyContent"
               Group="MyGroup"
               Description="Description of My Content Type"
               Inherits="FALSE"
               Overwrite="TRUE"
               Version="0">
    <FieldRefs>
      <FieldRef ID="{52578fc3-1f01-4f4d-b016-94ccbcf428cf}" DisplayName="Comments" Name="Comments" Required="FALSE"/>
      <FieldRef ID="{956a1078-ec35-4c04-83c4-0a3742119496}" Name="TimeTrackerTaxonomyTextField"/>
      <FieldRef ID="{92BC866B-0415-45F0-B431-D4DF69C421CC}" DisplayName="Tags" Name="Tags" Required="FALSE"/>
    </FieldRefs>
  </ContentType>
</Elements>

最初の機能(機能Aと呼びます)の機能レシーバーで、これをプログラムで取得TaxonomyFieldし、事前に定義された用語セットから用語を取得するように構成されていることを確認します。

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    SPWeb web = GetWebObj(properties.Feature.Parent);
    Guid fieldId = new Guid("92BC866B-0415-45F0-B431-D4DF69C421CC");
    TaxonomyField field = web.Fields[fieldId] as TaxonomyField;
    string groupName = properties.Feature.Properties["TaxonomyGroupName"].Value;
    string termSetName = properties.Feature.Properties["TermSetName"].Value;
    DiagnosticService logger = DiagnosticService.Local;

    TermSet set = null;
    TaxonomySession session = new TaxonomySession(web.Site);
    TermSetCollection termSets = session.GetTermSets(termSetName, System.Threading.Thread.CurrentThread.CurrentUICulture.LCID);
    if (termSets == null || termSets.Count == 0)
    {
        logger.WriteTrace(1, logger[CategoryId.Deployment], TraceSeverity.Medium,
            "Activity Tags term set not found.  Ensuring '{0}' group and '{1}' term set.", groupName, termSetName);
        // create the term set in the default store
        var store = session.DefaultSiteCollectionTermStore;
        var group = store.EnsureGroup(groupName);
        set = group.EnsureTermSet(termSetName);

        store.CommitAll();
        logger.WriteTrace(1, logger[CategoryId.Provisioning], TraceSeverity.Verbose, "created taxonomy group '{0}' and term set '{1}'", group, set);
    }
    else
    {
        logger.WriteTrace(1, logger[CategoryId.Deployment], TraceSeverity.Verbose, "term set found.");
        // need to make sure we grab the one in the right group, or it might be someone else's term set.                
        foreach (var termSet in termSets)
        {
            if (String.Equals(termSet.Group.Name,groupName))
            {
                if (set == null)
                {
                    set = termSet;
                }
                else
                {
                    logger.WriteTrace(1, logger[CategoryId.Deployment], TraceSeverity.Unexpected,
                        "Multiple term sets named '{0}' found in more than one taxonomy group.", termSetName);
                    throw new SPException(String.Format("Multiple term sets named '{0}' found in more than one taxonomy group.  "+
                                                        "Was there a previous installation that was not removed properly?", termSetName));
                }
            }
        }

        if (set == null)
        {
            // term set found, but in an unrecognized group.  leave it alone and do like above
            logger.WriteTrace(1, logger[CategoryId.Deployment], TraceSeverity.Verbose,
                "Term set '{0}' found, but in unrecognized group.  Provisioning new group and term set as configured.", termSetName);
            var store = session.DefaultSiteCollectionTermStore;
            var group = store.EnsureGroup(groupName);
            set = group.EnsureTermSet(termSetName);

            store.CommitAll();
            logger.WriteTrace(1, logger[CategoryId.Provisioning], TraceSeverity.Verbose, "created taxonomy group '{0}' and term set '{1}'", group, set);
        }
    }

    // set termSets to the newly created term set                
    field.SspId = set.TermStore.Id;
    field.TermSetId = set.Id;
    field.TargetTemplate = String.Empty;
    field.AnchorId = Guid.Empty;
    field.Open = true;
    field.AllowMultipleValues = true;
    field.Update();
}

2番目の機能には、リストテンプレートとインスタンスが含まれ、そのうちの1つは上記のコンテンツタイプを使用します。この機能を機能Bと呼びましょう。

プロビジョニング時に爆発するリストのリストスキーマは次のとおりです(ListInstance要素は表示されていません)。

<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" Title="My List" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/MyList" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
  <MetaData>
    <ContentTypes>      
      <ContentTypeRef ID="0x0100b61c774f4c0e4a89bf230cbb44cd4f75"></ContentTypeRef>
    </ContentTypes>

    <Fields> 
      <Field ID="{956a1078-ec35-4c04-83c4-0a3742119496}" Name="TaxonomyTextField" Type="Note"/>      
      <Field ID="{92bc866b-0415-45f0-b431-d4df69c421cc}" Name="Tags" Type="TaxonomyFieldType"/>
      <Field ID="{52578FC3-1F01-4f4d-B016-94CCBCF428CF}" Name="_Comments" Type="Note"/>      
    </Fields>
    <Views>
      <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
        <Toolbar Type="Standard" />
        <XslLink Default="TRUE">main.xsl</XslLink>
        <RowLimit Paged="TRUE">30</RowLimit>
        <ViewFields>
          <!-- <FieldRef Name="Tags"></FieldRef> -->
          <FieldRef Name="_Comments"></FieldRef>
        </ViewFields>
        <Query>
          <OrderBy>
            <FieldRef Name="ID">
            </FieldRef>
          </OrderBy>
        </Query>
        <ParameterBindings>
          <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
          <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
        </ParameterBindings>
      </View>
    </Views>
    <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>

ソリューションが展開された後、問題なく機能Aをアクティブ化できます。サイトの列とコンテンツタイプが作成されます。機能Bをアクティブ化しようとすると、機能アクティブ化の呼び出しスタックが爆発し、次のスタックトレースを含むエラーページが表示されます。

[COMException(0x80004005):このアクションを完了できません。

もう一度やり直してください。]
   Microsoft.SharePoint.Library.SPRequestInternalClass.UpdateField(String bstrUrl、String bstrListName、String bstrXML)+0
   Microsoft.SharePoint.Library.SPRequest.UpdateField(String bstrUrl、String bstrListName、String bstrXML)+134

[SPException:このアクションを完了できません。

もう一度やり直してください。]
   Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionListInstances(SPFeaturePropertyCollection小道具、SPSiteサイト、SPWeb Web、ブール値fForce)+23649702
   Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionElements(SPFeaturePropertyCollection props、SPWebApplication webapp、SPSiteサイト、SPWeb web、ブールfForce)+197
   Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent、SPWeb webParent、SPFeaturePropertyCollection小道具、ブール値fForce)+25437263
   Microsoft.SharePoint.SPFeatureCollection.AddInternal(SPFeatureDefinition featdef、バージョンバージョン、SPFeaturePropertyCollectionプロパティ、ブール値force、ブール値fMarkOnly)+27496735
   Microsoft.SharePoint.SPFeatureCollection.AddInternalWithName(Guid featureId、String featureName、バージョンバージョン、SPFeaturePropertyCollectionプロパティ、ブール値force、ブール値fMarkOnly、SPFeatureDefinitionScope featdefScope)+150
   Microsoft.SharePoint.SPFeatureCollection.Add(Guid featureId、ブール値、SPFeatureDefinitionScope featdefScope)+83
   Microsoft.SharePoint.WebControls.FeatureActivator.ActivateFeature(Guid featid、SPFeatureDefinitionScope featdefScope)+699
   Microsoft.SharePoint.WebControls.FeatureActivatorItem.BtnActivateFeature_Click(Object objSender、EventArgs evtargs)+140
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)+115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)+140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl、String eventArgument)+29
   System.Web.UI.Page.ProcessRequestMain(ブール値includeStagesBeforeAsyncPoint、ブール値includeStagesAfterAsyncPoint)+2981

機能ATaxonomyFieldでの構成方法に問題があることはかなり確信しています。プロビジョニング時のリストインスタンスとの関連付けがエラーの原因です(これは、コメントアウトして何度もデプロイすることで判断しました)。リストインスタンスでそれらをプロビジョニングするためのドキュメントやブロガーの経験はほとんどないようですので、少し戸惑っています。誰かが何が悪いのか考えていますか?TaxonomyFields

4

3 に答える 3

1

WictorWilénによるSharePoint2010管理メタデータ列のプロビジョニング方法に従い、同様の機能を得ることができました(このコメントからも変更を加えるようにしてください)。

于 2011-03-08T20:34:33.887 に答える
0

私はこれを理解するためにマイクロソフトとのサポートインシデントを開くことになりました。DisallowContentTypes="FALSE"最終的に、彼らのサービス担当者は、リストテンプレートとEnableContentTypes="TRUE"リストスキーマにプロパティを設定するまで追跡しました。これでプロビジョニングの問題は解決しました。

ただし、分類フィールド(grrr)に付随する必要がある非表示のテキストフィールドに関係して、新しくプロビジョニングされたリストに実際にアイテムを作成できるという問題がまだあります。サイトにメモフィールドをプロビジョニングし、リストテンプレートでそれを参照し、サイトの列定義とフィールド定義の両方でTextFieldプロパティをこのメモフィールドのIDに設定しました。

Wictorはそれについて言及しています(彼の投稿を読んだことを思い出すと)が、もっとここにあります:http: //www.sharepointconfig.com/2011/03/the-complete-guide-to-provisioning-sharepoint-2010-managed-メタデータ-フィールド/

私は現在、アイテムの作成時にスローされる例外に固執しています。

「ManagedMetadata」フィールドタイプコントロールから「Tags」列の値を取得できませんでした。ログで詳細を参照してください。例外メッセージ:無効なフィールド名。{956a1078-ec35-4c04-83c4-0a3742119496} http:// server / sites / mysite / sites / mysite / Lists / Entries

于 2011-03-08T22:30:42.003 に答える
0

カスタムContentTypeRefを含むサンドボックス化されたカスタムリストテンプレートのListInstance要素を含むサンドボックス化された機能をアクティブ化すると、同じエラーが発生します。リストは作成されますが、機能は作成時にエラーになります。さらに、リストには、リスト定義で指定されたものではなく、自動生成されたコンテンツタイプが含まれています。すべてのリストが作成されるまで機能をアクティブ化しようとすると、機能は最終的にアクティブ化されます。

さらに、MOSS 2010のSandBoxedソリューションからサンドボックス化されたカスタムフィールドプロパティを更新できないことに気付きました。サンドボックス化されたXMLを介して定義されたカスタムフィールドでSPListItem.UpdateFieldが呼び出されると、アクションを完了できないことを示す同じタイプのエラーが発生します。解決。

サンドボックス化されたフィールドの更新は、MOSS2010のサンドボックス化されたソリューションではサポートされていないと結論付けています。

サンドボックス化されたカスタムコンテンツタイプからフィールドをプログラムで更新する代わりに、XMLフィールド定義とリストテンプレートフィールドのXML要素でフィールドを完全に定義する必要があります。

「このアクションを完了できません」エラーを発生させずに、リストでカスタムコンテンツタイプを使用してアクティブ化する方法は、次のとおりです。

1)作成したカスタムの代わりに、リスト定義でデフォルトのContentTypeRefを使用します。

https://msdn.microsoft.com/en-us/library/office/ms452896(v=office.14).aspx

例:0x01デフォルトのアイテムコンテンツタイプ

0x0101デフォルトのドキュメントコンテンツタイプ

List Schema.xmlファイルで、コンテンツタイプがデフォルトのアイテムコンテンツタイプに基づいている場合は、次のように変更します。

<ContentTypes>
    <ContentTypeRef ID="0x01"></ContentTypeRef>
</ContentTypes>

2)コードを実行する機能に機能アクティブ化イベントレシーバーを追加して、リストのコンテンツタイプを構成します。

基本的にリストのコンテンツタイプを設定し、リストに関連付けられている他のコンテンツタイプを削除する関数を作成しました。機能アクティベーションイベントレシーバーは、この関数を実行して、リストのコンテンツタイプを本来あるべきものに設定できます。以下の関数は、コンテンツタイプに一意の名前が付けられていることを前提としています。必要に応じて、コンテンツタイプグループ名のチェックを追加することもできます。

       public static string ConfigureCustomListForCustomContentType(SPWeb web, string strListName, string strCustomContentTypeName)
    {
        StringBuilder sbOutput = new StringBuilder();
        try
        {
            SPList customlist = web.Lists[strListName];

            SPContentType CustomContentType = null;
            //Validate Content Types
            //1) Find the Content Type in the Content Type list
            foreach (SPContentType spct in web.Site.RootWeb.ContentTypes)
            {
                if (spct.Name == strCustomContentTypeName)
                {
                    CustomContentType = spct;
                    break;
                }
            }

            if (CustomContentType == null)
            {
                sbOutput.Append("<div class='error'>Unable to find custom content type named " + strCustomContentTypeName +".</div>");
                return sbOutput.ToString();
            }
            sbOutput.Append("Found content Type "+CustomContentType.Name+"...<br />");

            Boolean bFoundContentType = false;


            customlist.ContentTypesEnabled = true;

            List<SPContentTypeId> RemoveContentTypeList = new List<SPContentTypeId>();
            //Remove all other content types
            foreach (SPContentType spct in customlist.ContentTypes)
            {
                if (spct.Name == strCustomContentTypeName)
                {
                    bFoundContentType = true;
                }
                else
                {
                    RemoveContentTypeList.Add(spct.Id);
                }

            }


        if (!bFoundContentType)
            {
                sbOutput.Append("Adding [" + strCustomContentTypeName + "] to List " + customlist.Title + "<br />");
                customlist.ContentTypes.Add(CustomContentType);
            }
            else
            {
                sbOutput.Append("[" + strCustomContentTypeName + "] already in List " + customlist.Title + ".<br />");
            }

            for (int i = 0; i < RemoveContentTypeList.Count; i++)
            {

                sbOutput.Append("Removing extra content type: " + customlist.ContentTypes[RemoveContentTypeList[i]].Name + "<br />");
                customlist.ContentTypes[RemoveContentTypeList[i]].Delete();
            }


        }
        catch (Exception ex)
        {
            sbOutput.Append("<div class='error'>Error occurred configuring "+strListName+": " + ex.ToString() + "<br /></div>");
        }

        return sbOutput.ToString();

    }

これにより、リストをインスタンス化し、コンテンツタイプをカスタムコンテンツタイプに設定できるようになります。

リストがイベントタイプ0x0102に基づいている場合、サンドボックスソリューションでエラーが発生しない限り、上記の関数が機能しない可能性があります。

イベントタイプについては、デフォルトのイベントコンテンツタイプを使用し、コードを実行して、必要に応じてリストをカスタマイズ(列を追加)しました。

于 2015-10-16T09:14:05.133 に答える