动态分发组查看器 (Sharepoint 2010 WebPart)






4.11/5 (3投票s)
允许用户查看哪些用户属于 Exchange 动态分发组
引言
许多组织/公司在 Exchange 中使用动态分发组。虽然这些组允许较低的管理开销,但它们不允许用户在发送电子邮件之前知道邮件将发送给谁。这个 Sharepoint WebPart 允许用户在发送电子邮件之前查看组中的成员。
Using the Code
在开始之前,您必须在服务器上安装 Exchange 管理控制台。如果您计划在 Sharepoint 中部署此 WebPart,还需要编辑您的 web.config 文件,使其包含
<trust level="Full" originUrl="" />
在 Visual Studio 2010 中,创建一个新的空 SharePoint 项目。添加一个新的 Visual Web Part 项目。将 System.Management.Automation
引用添加到您的项目。在您的 using
语句中包含以下 3 个项目:
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Management.Automation.Runspaces;
我们需要打开 Exchange 管理 PowerShell snapin。
RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
PSSnapInException snapInException = null;
PSSnapInInfo info = rsConfig.AddPSSnapIn
("Microsoft.Exchange.Management.PowerShell.Admin", out snapInException);
Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsConfig);
myRunSpace.Open();
接下来,我们需要将 cmdlet
发送到 PowerShell。在这种情况下,我请求 Get-DynamicDistributionGroup
,并将 groupName
设置为用户从下拉列表中选择的变量。
Pipeline pipeLine = myRunSpace.CreatePipeline();
Command myCommand = new Command("Get-DynamicDistributionGroup");
CommandParameter identityParam = new CommandParameter("Identity", groupName);
myCommand.Parameters.Add(identityParam);
pipeLine.Commands.Add(myCommand);
Collection<PSObject> commandResults = pipeLine.Invoke();
PSObject distGroup = commandResults[0];
Runspace recipientRunSpace = RunspaceFactory.CreateRunspace(rsConfig);
recipientRunSpace.Open();
一旦我们获得了动态分发组的名称,我们就需要它的收件人。
pipeLine = recipientRunSpace.CreatePipeline();
myCommand = new Command("Get-Recipient");
if (distGroup.Members["RecipientFilter"] != null &&
distGroup.Members["RecipientFilter"].Value.ToString().Length > 0)
{
CommandParameter recipientFilter = new CommandParameter
("RecipientPreviewFilter", distGroup.Members["RecipientFilter"].Value);
myCommand.Parameters.Add(recipientFilter);
}
CommandParameter OU = new CommandParameter("OrganizationalUnit", distGroup.Members
["RecipientContainer"].Value.ToString());
myCommand.Parameters.Add(OU);
pipeLine.Commands.Add(myCommand);
commandResults = pipeLine.Invoke();
接下来,我构建该组中所有用户名称的列表。然后将名称列表绑定到项目符号列表。
List<string> nameList = new List<string>();
foreach (PSObject cmdlet in commandResults)
{
if (cmdlet.Properties["Name"] != null &&
cmdlet.Properties["Name"].Value.ToString().Length > 0)
{
string recipientName = cmdlet.Properties["Name"].Value.ToString();
nameList.Add(recipientName);
}
}
BulletedList1.DataSource = nameList;
BulletedList1.DataBind();
我做的最后一件事情是更改项目符号列表的 DisplayMode
为 LinkButton
。这会将用户名称变成指向 Sharepoint MySite 页面的超链接。
protected void BulletedList1_Click(object sender, BulletedListEventArgs e)
{
ListItem li = BulletedList1.Items[e.Index];
Response.Redirect("http://sharepoint peoplesearch URL"
+ BulletedList1.Items[e.Index].Text);
}
历史
- 2010 年 12 月 8 日:初始发布