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 }
作者:Statmoon
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。