SharePoint 2007在Web部件中发布站点和受众定位

时间:2009-04-17 09:29:13

标签: sharepoint moss caml

在发布网站中,我的网页部分必须显示具有“受众群体定位”字段的列表中的新闻项目。我正在使用CAML查询来检索少量的最新消息。

是否可以在CAML查询中指定目标受众?如果没有,我应该怎么做?检索所有结果,然后在循环中应用过滤器?

我实际上复制了内容查询Web部件,我需要在自定义Web部件中使用受众群体定位。

2 个答案:

答案 0 :(得分:1)

不,无法在CAML查询中指定受众群体定位。我认为这与作为WSS事物的CAML查询和作为MOSS共享服务的Audiences有关。您需要做的是在CAML查询中包含受众群体字段,即添加< FieldRef Name ='Target_x0020_Audiences'/>到SPQuery.ViewFields属性。然后按照每个列表项的受众对代码进行过滤。使用AudienceManager类测试当前用户是否是受众的成员。

答案 1 :(得分:0)

我找到了解决方法,在尝试检查当前用户是否是特定发布页面的受众群体以及该受众的名称时,我遇到了一个问题。这是我提出的解决方法。


// Run through the pages building the list items
foreach (SPListItem li in pages)
{
  // Get a reference to the publishing page
  PublishingPage p = PublishingPage.GetPublishingPage(li);

  // Make sure the page has been approved
  if (li.ModerationInformation.Status == SPModerationStatusType.Approved)
  {
    // Check if this page has an audience
    if (string.IsNullOrEmpty(p.Audience))
      // Add to everyone list
    else
    {
      // Split the audiences
      string[] Audiences = p.Audience.Split(';');

      // Check each audience to see if this user can see it
      foreach (string audPart in Audiences)
      {
        AudienceManager audienceManager = new AudienceManager();

        // Get a reference to the audience
        // IsGuid is an extenstion method i wrtoe
        if (audPart.IsGuid())
        {
          if (audienceManager.Audiences.AudienceExist(new Guid(audPart)))
            aud = audienceManager.Audiences[new Guid(audPart)];
        }
        else
        {
          if (audienceManager.Audiences.AudienceExist(audPart))
            aud = audienceManager.Audiences[audPart];
        }

        // Ensure we have a reference to the audience
        if (aud != null)
        {

          // store the item in the temp variables
          switch (aud.AudienceName)
          {
            case "All site users":
              // Add to everyone list
              break;

            case "Some List":
              if (audienceManager.IsMemberOfAudience(web.CurrentUser.LoginName, aud.AudienceID))
              {
                // Add to other list
              }
              break;

            case "Other List":
              if (audienceManager.IsMemberOfAudience(web.CurrentUser.LoginName, aud.AudienceID))
              {
                // Add to other list
              }
              break;
          }

        }
      }
    }
  }
}

正如您所看到的那样,通过使用AudienceManager.Audiences.AudienceExist并通过使用默认访问者AudienceManager.Audiences [GUID]来获取对它的引用,它确实只是检查受众是否存在的主要内容;

相关问题