SharePoint中低权限用户通过提升权限创建用户组

主要代码如下:

 1         /// <summary>
2 /// 提升权限创建用户组
3 /// </summary>
4 /// <param name="groupname">用户组的名字</param>
5 public void CreateGroup(string groupname)
6 {
7 SPSecurity.RunWithElevatedPrivileges(delegate()
8 {
9 try
10 {
11 using (SPSite mySite = new SPSite(SPContext.Current.Site.ID))
12 {
13 using (SPWeb myWeb = mySite.OpenWeb())
14 {
15 myWeb.AllowUnsafeUpdates = true;
16 myWeb.SiteGroups.Add(groupname, myWeb.CurrentUser, null, "");
17 myWeb.AllowUnsafeUpdates = false;
18 }
19 }
20 }
21 catch (Exception ex)
22 {
23 //throw custom exception
24 }
25 });
26 }

 

posted @ 2012-01-05 22:40  Statmoon  阅读(480)  评论(0编辑  收藏  举报