SharePoint中的"用户或用户组"栏
来源:互联网 发布:有哪些经济数据库 编辑:程序博客网 时间:2024/06/05 20:01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//从SPListItem中取SPUser方法、代码
处理Sharepoint中的SPListItem时,有时需要获得这个对象的
"Created By"
(创建者),并且希望是SPUser类型,而不是
string
,这样可以进而得到该用户的权限、ID等等。
"Person or Group"
(用户或组)对应的类型是SPFieldUser,怎么把SPFieldUser转成SPUser呢?
网上找了些资料,发现要获得SPUser需要借助SPFieldUserValue,借鉴了一些代码,自己试了试,写了一个通用的方法:
SPUser GetSPUserFromSPListItemByFieldName(SPListItem spItem,
string
fieldName)
{
string
userName = spItem[fieldName].ToString();
SPFieldUser _user = (SPFieldUser)spItem.Fields[fieldName];
SPFieldUserValue userValue = (SPFieldUserValue)_user.GetFieldValue(userName);
return
userValue.User;
}
//SharePoint中的"用户或用户组"栏,当选择了"允许多重选择"后,用对象模型SPListItemCollection["栏名"]获得到的是SPFieldUserValueCollection的对象:
SPFieldUserValueCollection users = SPListItem[
"栏名"
]
as
SPFieldUserValueCollection;
如果将SPListItemCollection[
"栏名"
]输入字符串的话,是
"用户ID;#用户Name"
,
一 为栏赋值有这几种方式,
SPListItem[
"栏名"
] = SPUser实例或者SPGroup实例,但是不能赋SPUserCollection;
SPListItem[
"栏名"
] =
"用户ID;#用户Name;#用户ID;#用户Name......"
;
SPListItem[
"栏名"
] = SPFieldUserValueCollection实例;(当栏设置允许多重选择为否时,赋的值都是集合中的第一个)
SPListItem[
"栏名"
] = SPFieldUserValue实例;
二 获取栏的值
当栏设置为
"允许多重选择"
为否时,不管用SPFieldUserValueCollection userValues=item[
"栏名"
]
as
SPFieldUserValueCollection;还是SPFieldUserValue userValue = item[
"栏名"
]
as
SPFieldUserValue;得到的值都是Null;
如果想判断是否选择了
"允许多重选择"
,可以先查看SPFieldUser字段的AllowMutipleValues属性.不过真麻烦.
实际上在该字段在
"允许多重选择"
为否时,字段类型是
string
,为是时,字段类型是SPFieldUserValueCollection.
protected
void
btnOK_Click(
object
sender, EventArgs e)
{
ArrayList list = PeopleEditor1.ResolvedEntities;
string
msgTo =
""
;
//获取id和显示名称
foreach
(Microsoft.SharePoint.WebControls.PickerEntity p
in
list)
{
string
userId = p.EntityData[
"SPUserID"
].ToString();
msgTo += userId +
"#"
;
}
//获取帐号
ArrayList selectedAccoutList = PeopleEditor1.Accounts;
string
selectedAccouts2 = PeopleEditor1.CommaSeparatedAccounts;
SPSecurity.RunWithElevatedPrivileges(
delegate
()
{
if
(msgTo !=
""
)
{
for
(
int
i = 0; msgTo.Length > 1; i++)
{
string
lassmsgto =
string
.Empty;
lassmsgto = msgTo.Substring(msgTo.IndexOf(
"#"
) + 1);
msgTo = msgTo.Substring(0, msgTo.IndexOf(
"#"
));
SPSite site =
new
SPSite(SPContext.Current.Site.Url);
SPWeb web = site.RootWeb;
.AllowUnsafeUpdates =
true
;
web.AllowUnsafeUpdates =
true
;
SPListItem item = web.Lists[
"Messageboard"
].Items.Add();
item[
"ToNameID"
] = msgTo;
item[
"Content"
] =
this
.txtContent.Text.Trim();
item[
"Title"
] =
this
.txtTitle.Text.Trim();
SPFieldUserValue userValue =
new
SPFieldUserValue(web,msgTo);
item[
"ToName"
] = userValue;
item.Update();
web.AllowUnsafeUpdates =
false
;
site.AllowUnsafeUpdates =
false
;
msgTo = lassmsgto;
}
}
});
GridView1Show();
}
- SharePoint中的"用户或用户组"栏
- SharePoint中的"用户或用户组"栏
- SharePoint对象模式获取“用户或用户组”栏的值
- SharePoint对象模式获取“用户或用户组”栏的值
- sharepoint 判断用户在用户组
- sharepoint 添加用户组,获取用户组集合中的用户组
- 关于SharePoint 2007的用户组和用户
- 关于SharePoint 2007的用户组和用户
- 关于SharePoint 2007的用户组和用户
- 关于SharePoint 2007的用户组和用户
- SharePoint 检查当前用户是否在某sharePoint用户组中
- linux中的用户和用户组
- Linux中的用户与用户组
- Linux中的用户和用户组
- sharepoint 2010 验证用户组是否存在当前用户 IsCurrentUserMemberOfGroup
- sharepoint 2010 判断当前用户是否为用户组成员
- Linux中的用户和用户组管理
- 查看centos中的用户和用户组
- MIT/GNU Scheme用户手册(三)
- zend framework之router 路由器设置
- [开源]Android手机控制电脑----服务器端
- WebKit for Developers
- oracle 调用webservice
- SharePoint中的"用户或用户组"栏
- 关于GPIO
- oracle自增auto_increment与oracle 创建触发器是非法的 ORA-04098: trigger 'USER_TRIGGER'is invalid and failed re-v
- 关于总线、设备、驱动
- ogre学习1——ogreSingleton类
- 数据类型不一致导致的SQL不走索引
- channelartlist 支持currentstyle属性
- JavaEE---Servlet会话跟踪之Cookie
- CSS代码