SharePoint 2007 发布网站和 Web 部件中的受众定位

发布于 2024-07-17 09:43:20 字数 215 浏览 7 评论 0原文

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

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

我实际上是在复制内容查询 Web 部件,并且我需要在自定义 Web 部件中进行受众定位。

In a Publishing site I have web part that has to show news items from the list that has Audience Targeting field. I am using CAML query to retrieve small number of last news items.

Is it possible to specify Target Audience in the CAML query ? If not, how should I do it ? Retrieve all results and than apply filter in a loop ?

I am practically duplicating Content Query Web Part and I need Audience Targeting in my custom web part.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇纵 2024-07-24 09:43:20

不可以,无法在 CAML 查询中指定受众群体定位。 我认为这与 CAML 查询是 WSS 的事情以及受众是 MOSS 共享服务有关。 您要做的就是在 CAML 查询中包含受众字段,即添加一个到 SPQuery.ViewFields 属性。 然后按每个列表项上的受众明智地过滤结果代码。 使用 AudienceManager 类测试当前用户是否是受众的成员。

No, it is not possible to specify audience targeting in a CAML query. I think this has to do with CAML queries being a WSS thing and Audiences being a MOSS Shared Service. What you have to do is to include the audience field in the CAML query, i.e. add a <FieldRef Name='Target_x0020_Audiences'/> to the SPQuery.ViewFields property. Then filter the results code wise by audience on each list item. Use the AudienceManager class to test if the current user is a member of an audience.

埋葬我深情 2024-07-24 09:43:20

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


// 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] 获取对它的引用;

Well i found a workaround for this, i was experiencing an issue when trying to check if the current user was a memeber of the audience for a specific publishing page and what the name of that audience was. Here is the workaround i came up with.


// 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;
          }

        }
      }
    }
  }
}

As you can see its really just a mater of checking if the audience exists by using AudienceManager.Audiences.AudienceExist and the getting a reference to it by just using the default accesor AudienceManager.Audiences[GUID];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文