Audience Audience Audience Audience Class
Definition
Represents an audience on a SharePoint site.
public ref class Audience
public class Audience
type Audience = class
Public Class Audience
- Inheritance
Examples
This code example shows how to create a rules-based audience to which you can target content.
Note: The audience is only created here; it is not compiled, and rules have not been added. You can add rules by using the user interface or the object model, and then compile the audience by using the user interface. Compiling audiences is not supported in the object model.
Replace servername and other strings with actual values before running the code example. Also add the following references in your Visual Studio project:
- Microsoft.Office.Server
- Microsoft.SharePoint
- System.Web
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.Server.Audience;
using Microsoft.SharePoint;
using Microsoft.Office.Server;
using System.Web;
namespace AudienceConsoleApp
{
class Program
{
static void Main(string[] args)
{
try
{
using (SPSite site = new SPSite("http://<span class="placeholder">servername</span>"))
{
ServerContext context = ServerContext.GetContext(site);
AudienceManager audManager = new AudienceManager(context);
AudienceCollection ac = audManager.Audiences;
Audience a = null;
string sAudName = "Customer Connection";
string sDescription = "Members of the Customer Connection v-team";
try
{
a = ac.Create(sAudName, sDescription);
}
catch (AudienceDuplicateNameException e)
{
//Add your exception handling code here.
}
catch (AudienceException e1)
{
//Add your exception handling code here.
}
}
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
Console.Read();
}
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SharePoint.Administration
Imports Microsoft.Office.Server.Audience
Imports Microsoft.SharePoint
Imports Microsoft.Office.Server
Imports System.Web
Namespace AudienceConsoleApp
Module Program
Sub Main(ByVal args() As String)
Try
Using site As New SPSite("http://servername")
Dim context As ServerContext = ServerContext.GetContext(site)
Dim audManager As New AudienceManager(context)
Dim ac As AudienceCollection = audManager.Audiences
Dim a As Audience = Nothing
Dim sAudName As String = "Customer Connection"
Dim sDescription As String = "Members of the Customer Connection v-team"
Try
a = ac.Create(sAudName, sDescription)
Catch e As AudienceDuplicateNameException
'Add your exception handling code here.
Catch e1 As AudienceException
'Add your exception handling code here.
End Try
End Using
Catch exception As Exception
Console.WriteLine(exception.ToString())
Console.Read()
End Try
End Sub
End Module
End Namespace
Remarks
Audiences are groups of users determined by their memberships in Microsoft Exchange distribution lists (DL) or SharePoint groups, or by rules configured by a portal administrator. For example, you can set up new employees, executives, salespeople, or people from a specified city as audiences. You can base the audience rules on information in the user profile, on membership in an Active Directory directory service security group or an Exchange distribution list, or on the organization's reporting structure (if this information is kept in Active Directory).
Audiences allow organizations to target content to users based on their job or task, as defined by their membership in a SharePoint group or distribution list, by the organizational reporting structure, or by the public properties in their user profiles.
You can target based on audience, SharePoint groups, and DL memberships. In addition, you can target the list-item level, rather than just the list level.
Properties
AudienceDescription AudienceDescription AudienceDescription AudienceDescription |
Gets or sets the description for this audience. |
AudienceID AudienceID AudienceID AudienceID |
Gets the GUID for this audience. |
AudienceName AudienceName AudienceName AudienceName |
Gets or sets the name of this audience. |
AudienceRules AudienceRules AudienceRules AudienceRules |
Gets or sets an array of AudienceRuleComponent objects that represents rules that define this audience. |
AudienceSite AudienceSite AudienceSite AudienceSite |
Gets the URL for the portal site associated with this audience. |
CreateTime CreateTime CreateTime CreateTime |
Gets the date when this audience was created. |
GroupOperation GroupOperation GroupOperation GroupOperation |
Gets or sets a member of the AudienceGroupOperation enumeration that indicates the group operation that applies to this audience. |
LastCompilation LastCompilation LastCompilation LastCompilation |
Gets the date when the rules for this audience were last compiled. |
LastError LastError LastError LastError |
Gets last error message that occurred during rule compilation. |
LastPropertyUpdate LastPropertyUpdate LastPropertyUpdate LastPropertyUpdate |
Gets the date when the audience properties were last changed. |
LastRuleUpdate LastRuleUpdate LastRuleUpdate LastRuleUpdate |
Gets the date when the rules for this audience were last updated. |
MemberShipCount MemberShipCount MemberShipCount MemberShipCount |
Gets the membership count for this audience. |
OwnerAccountName OwnerAccountName OwnerAccountName OwnerAccountName |
Gets or sets the owner account name for this audience. |
Methods
Commit() Commit() Commit() Commit() |
Saves all changes to audience data in the database, such as updated name, description, and operator list. |
GetMembership() GetMembership() GetMembership() GetMembership() |
Gets an ArrayList of UserInfo objects that contains membership information for this audience. |
IsMember(String) IsMember(String) IsMember(String) IsMember(String) |
Determines whether a user is a member of this audience. |
ReloadMembership() ReloadMembership() ReloadMembership() ReloadMembership() |
Causes the server to reload the membership information for this audience. |
Extension Methods
ToJson(Object) ToJson(Object) ToJson(Object) ToJson(Object) |
Applies to
Commentaires
Nous aimerions avoir votre avis. Choisissez le type d’avis que vous souhaitez fournir :
Notre système de commentaires est basé sur l’infrastructure de problèmes GitHub. Apprenez-en davantage sur notre blog.
Chargement du commentaire...