0

CQWP の "Grouped by" プロパティをプログラムで変更するために、SPLimitedWebPartManager を使用してコンテンツ クエリ Web パーツの Web パーツ プロパティにアクセスしています... 残念ながら、その特定のプロパティにアクセスする方法がわかりません。タイトル、説明などを変更できますが、グループ化/並べ替えのプロパティは変更できません...これを行う方法の手がかりはありますか?

コードは次のとおりです。

SPFile ofile = page.File;

SPLimitedWebPartManager wpColl = ofile.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.User);
int cont = wpColl.WebParts.Count;

Console.WriteLine("    - " + page.Name);

for (int i = 0; i < cont; i++)
{
    System.Web.UI.WebControls.WebParts.WebPart wp1 = wpColl.WebParts[i];

    Console.WriteLine("        Personal: " + wp1.ToString());
    Console.WriteLine("        - Title: " + wp1.Title);
    Console.WriteLine("        - ID: " + wp1.ID);

    if (wp1.Title.Equals("CQWP Title"))
    {
        wp1.Title = "WebPart_CQWP";
        Console.WriteLine("        - New Title " + wp1.Title);

        // ----- here I would like to add the same thing to update the Group By property (or any other property which would be useful in order to configure the CQWP (list, type of document we are filtering, etc...) ---- how can I do that?
    }

    ofile.Update();
    wpColl.SaveChanges(wp1);
}

ありがとうございました!

4

1 に答える 1

0

わかりました、それを行う方法を見つけました。この Web パーツの正確な設定にアクセスするには、実際にこの Web パーツを CQWP としてキャストする必要がありました。以下をコードに追加しました。

Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart cqwp = (Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart)wp1;

                                    Console.WriteLine("................." + cqwp.GroupBy);

これで、Web パーツの GroupBy プロパティにアクセスできるようになりました。これは、他の方法では使用できません。

于 2012-06-01T11:19:09.437 に答える