【问题标题】:How can I access through code the Grouping property for a Content Query Web Part in SharePoint 2010?如何通过代码访问 SharePoint 2010 中内容查询 Web 部件的分组属性?
【发布时间】:2012-06-01 19:19:09
【问题描述】:

我正在使用 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);
}

谢谢!

【问题讨论】:

    标签: c# sharepoint-2010 cqwp


    【解决方案1】:

    好的,找到方法了。 实际上,我需要将此 Web 部件转换为 CQWP,以便访问它的确切设置。在代码中添加以下内容:

    Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart cqwp = (Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart)wp1;
    
                                        Console.WriteLine("................." + cqwp.GroupBy);
    

    现在我可以访问我的 webpart 的 GroupBy 属性,否则该属性不可用。

    【讨论】:

      猜你喜欢
      • 2011-11-09
      • 1970-01-01
      • 2011-02-08
      • 1970-01-01
      • 2016-10-09
      • 2011-09-16
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      相关资源
      最近更新 更多