Nirvanalst
博客园
闪存
首页
新随笔
联系
管理
订阅
随笔- 23 文章- 0 评论- 28
2009年11月3日
通过程序将UserProfile中用户导入到指定SharePoint用户组
Code
1
using
(SPSite site
=
new
SPSite(
"
http://itsmossserver:81
"
))
2
{
3
//
用户组
4
SPGroup sealerGroup
=
site.RootWeb.SiteGroups[
"
销售人员
"
];
5
ServerContext context
=
ServerContext.GetContext(site);
6
UserProfileManager profiles
=
new
UserProfileManager(context);
7
//
出现异常日志
8
StreamWriter writer
=
File.CreateText(
"
d:\\userLog.txt
"
);
9
string
loginName
=
""
;
10
string
dispName
=
""
;
11
string
email
=
""
;
12
//
遍历UserProfile集合
13
foreach
(UserProfile profile
in
profiles)
14
{
15
try
16
{
17
loginName
=
profile.MultiloginAccounts[
0
];
18
dispName
=
profile[
"
PreferredName
"
].ToString();
19
email
=
profile[
"
UserName
"
].ToString()
+
"
@dc.com
"
;
20
//
向用户组添加用户
21
sealerGroup.AddUser(loginName, email, dispName,
""
);
22
Console.WriteLine(profile.MultiloginAccounts[
0
]
+
"
;
"
+
dispName
+
"
OK!
"
);
23
}
24
catch
(Exception)
25
{
26
writer.WriteLine(loginName
+
"
#
"
+
dispName);
27
}
28
}
29
writer.Dispose();
30
writer.Close();
31
}
posted @ 2009-11-03 11:42 nirvanalst 阅读(273) 评论(0)
编辑
公告