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 }
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 }