程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> moss 人員選擇器PeopleEditor使用基礎教程

moss 人員選擇器PeopleEditor使用基礎教程

編輯:關於C#
 

要在MOSS中開發一個有用戶選擇功能的頁面或webpart,就要用到PeopleEditor 控件了

頁面聲明如下:
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<SharePoint:PeopleEditor id="PeopleEditor1" runat="server"
SelectionSet="User"
ValidatorEnabled="true"
AllowEmpty = "false"
MultiSelect = "true"
/>
這樣,就能顯示出標准的用戶選擇界面了.

接下來,我們如何獲取選擇的用戶數據呢?
ArrayList list = PeopleEditor1.ResolvedEntities ;
//獲取id和顯示名稱
foreach (Microsoft.SharePoint.WebControls.PickerEntity p in list)
{
string userId = p.EntityData["SPUserID"].ToString();
string DisplayName = p.EntityData["DisplayName"].ToString();
}
//獲取帳號
ArrayList selectedAccoutList = PeopleEditor1.Accounts;
string selectedAccouts2 = PeopleEditor1.CommaSeparatedAccounts;
設置初始選中用戶:
PeopleEditor1.CommaSeparatedAccounts = @"JYSERVER\spsadmin,JYSERVER\administrator";
測試代碼需要在moss的環境中運行,頁面放入_layouts文件夾,或寫到webpart中。

下面是一個完整的測試用webpart:
//test code by [email protected]
// 2008-11-10
//
//
using System;
using System.Collections;
using System.Text;
using sharepoint = Microsoft.SharePoint.WebControls ;
using wss = Microsoft.SharePoint.WebPartPages;
using System.Web.UI.WebControls ;
using System.Runtime.InteropServices;
using Microsoft.SharePoint;

namespace PeoplePickerTest
{
[Guid("8D64A4D3-8C9F-4a44-9720-611A701C0B79")]
public class MyPeoplePicker : wss.WebPart
{
private Microsoft.SharePoint.WebControls.PeopleEditor PeopleEditor1;
private Button btn;

protected override void CreateChildControls()
{
base.CreateChildControls();
PeopleEditor1 = new Microsoft.SharePoint.WebControls.PeopleEditor();
Controls.Add(PeopleEditor1);
btn = new Button();
btn.Text = "test";
Controls.Add(btn);
btn.Click += new EventHandler(btn_Click);
}

void btn_Click(object sender, EventArgs e)
{
Page.Response.Write( PeopleEditor1.CommaSeparatedAccounts );

ArrayList list = PeopleEditor1.ResolvedEntities ;
//獲取id和顯示明
foreach (Microsoft.SharePoint.WebControls.PickerEntity p in list)
{
string userId = p.EntityData["SPUserID"].ToString();
string DisplayName = p.EntityData["DisplayName"].ToString();
}

//獲取帳號
ArrayList selectedAccoutList = PeopleEditor1.Accounts;
string selectedAccouts2 = PeopleEditor1.CommaSeparatedAccounts;
//設置值
PeopleEditor1.CommaSeparatedAccounts = @"JYSERVER\spsadmin,JYSERVER\administrator";
}
}
}
 

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved