C# 如何在SharePoint 2010中通过代码访问内容查询Web部件的分组属性?

C# 如何在SharePoint 2010中通过代码访问内容查询Web部件的分组属性?,c#,sharepoint-2010,cqwp,C#,Sharepoint 2010,Cqwp,我正在使用SPLimitedWebPartManager访问内容查询Web部件的Web部件属性,以便通过编程方式修改CQWP的“分组依据”属性。。。不幸的是,我不知道如何访问该特定属性,我似乎能够修改标题、描述等。。。但不是分组/排序属性。。。你知道怎么做吗 代码如下: SPFile ofile = page.File; SPLimitedWebPartManager wpColl = ofile.GetLimitedWebPartManager(System.Web.UI.WebContro

我正在使用SPLimitedWebPartManager访问内容查询Web部件的Web部件属性,以便通过编程方式修改CQWP的“分组依据”属性。。。不幸的是,我不知道如何访问该特定属性,我似乎能够修改标题、描述等。。。但不是分组/排序属性。。。你知道怎么做吗

代码如下:

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);
}
Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart cqwp = (Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart)wp1;

                                    Console.WriteLine("................." + cqwp.GroupBy);
SPFile of ile=page.File;
SPLimitedWebPartManager wpColl=ofile.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.User);
int cont=wpColl.WebParts.Count;
Console.WriteLine(“-”+page.Name);
对于(int i=0;i
谢谢!

好的,找到了如何做。 我需要将此Web部件强制转换为CQWP,以便访问其确切设置。在代码中添加了以下内容:

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);
}
Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart cqwp = (Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart)wp1;

                                    Console.WriteLine("................." + cqwp.GroupBy);
现在,我可以访问我的Web部件的GroupBy属性,该属性在其他情况下不可用